Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp114849pxj; Mon, 17 May 2021 22:35:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlmT4q6ejt+vkpXYg2msPCc5UGnQKYGVnRrentiZMqkmKIVf9cZNZsv5LiYiVdjZqJYHjs X-Received: by 2002:a92:1304:: with SMTP id 4mr2743811ilt.126.1621316119667; Mon, 17 May 2021 22:35:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621316119; cv=none; d=google.com; s=arc-20160816; b=tndqF2bLePJWCXMfcPZhaj+Bw0oCNqqBc2H3Et4qGGffvP1qCQHooqcmYiyLbxVIo6 i2PST35M69S9AMBK3F4JxoZYNgGOY3y8bZaO92fd4ufD44eNlX0TUxacjHpCpbNiOLsv cbbicB0qZhxhTCnxRbbMpZkJijxEDb6+GZam98rL1wgbN/gT8yvQIWzdDreX7sN3DoM+ QIsxyd1hqcTBQxQZILPV8CtAE7cIrXQGchz09ZEjUM0E1xYBQtxWbZxKmlYWwpxoguTq 7OLN8k6vcSlm3FWgKLzZNRJqmIko2o2XdkjOn3nx2qKDaCdT7CCgr9fRXIZwYPAX2A+t fkyQ== 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=tB6uO49albGSXEo1EVvQPkC1dlb0K9gGIW7FYut8O12GGJwX6nYwLGLktJAUAQ6U7r mPSZR9W6rIaERG4duCD2UWEQP7+6AdT4UTxTRZsG7L3Fvi0+ygAbU7M0cp8Bh6ER7SyR 4wbyv2GnBjxl7C6TpAFChh93l5HW3XvU+YSE+k0LHz7E5yib0sKW50G9ZFVGdstbvv+r 2/KKCYxY992s+6y1G1mZtVUBl7FSVewjdlpSdVNR8ZvK+TqlRn2KRMoJN43T2HEev6kF 1KIxmPlSRI4ABJ3nh2p6FvE9dUDYYQomdTeFo6dzkDyi9t/xwM+Ta/+KrjSzyiODz6sD e9bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=19j4hvdi; 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 m8si7093041ilh.136.2021.05.17.22.35.07; Mon, 17 May 2021 22:35:19 -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=19j4hvdi; 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 S241140AbhEQOrF (ORCPT + 99 others); Mon, 17 May 2021 10:47:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:33968 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240874AbhEQOjU (ORCPT ); Mon, 17 May 2021 10:39:20 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 16DFD6139A; Mon, 17 May 2021 14:18:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621261104; bh=Y1Fi/8EmZWG4KsmdkBqPpUUPzppWQTtjsGwFkKKu/P0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=19j4hvdi+fDGmBa1H6CR/00j8vtQqkaPbHPPpzk5nuzqlCkHAOsHwr+JUCM2uDyMv D7R4Qr1jc3byZiR7+TqttI2HlqIdeBDlzEIgX8RKqCkTxpkW801iH2Lf7yAsJoQXuE IHBlGf0TtxRZIPs0dkwKPw1QmQ6XF5wG354FWJJY= 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.12 282/363] dax: Wake up all waiters after invalidating dax entry Date: Mon, 17 May 2021 16:02:28 +0200 Message-Id: <20210517140312.145203437@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.508966430@linuxfoundation.org> References: <20210517140302.508966430@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