Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp479741pxj; Tue, 18 May 2021 07:39:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw9QUKpF4HNymkHZlhqGluuOQAfkO0W+ktk4hiSYJHteOTaf8wxhFaBi4B9dWGh3njc7Llu X-Received: by 2002:a17:907:1749:: with SMTP id lf9mr6609732ejc.178.1621348763280; Tue, 18 May 2021 07:39:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621348763; cv=none; d=google.com; s=arc-20160816; b=Abc2iYPNKsEc9vfa+F9pd5bdo6b4cGQoltWl8DP+tFOvf8eWDuxC9J59t9oU5pZbgb SPKBUNjsnCoc2ijkNrUxrBt+o+Qti5Rd8ZJqszP7oz6liwSMO8qq24reJPK/QacnVsoO mJIfgEG6HFjRMHubmjsQnPLZJBv44IukdudL6UDTQSS1cdaJtjW6fTISRhU3o49VQdQ8 biejq93o8X1rR1ajGzKk6QhQvJ+ToIgqz4zhmJBxtnTd9MHoYdI3isMZhacPcXnByyqA kfe/MwI2GYyxhtrbCf/6KSGVYOdQY2GtUUj0XkuiTFIlCnunv8ZLQSfr+8Tx3O8JXVg4 pqSw== 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=N+bajYERFrpOKus4RWCMVLsG2lXacnJZ06gkJB2g8x7LX97AketbGedrnHgQmsKOkA ZIAroJX099Zk4fxi7G7ZEVl4UwZBYZJhGaqWocxWMszcT4MD0kqF/e5bE97k+QS5GiIy d043HVtez9OffoKzDLHQCn0lYeFLXAC68s6IOcfCEk30uFBSpg6KaUKgQ27skzeVvulh S9tanVA89Cy5R3Rj0Jly8luD4GBmv53d+oOKYhu8jQooIN+XZyC+UiC0+aefIyGJ368g nb9CxwTxtmOs8mzw0tsKL5NCVMm8fpFebXsjzEjpomB8rvzyGalHIHsSJBsdLrRWUnpO 1wOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kldb5Xv3; 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 s18si3778247eji.59.2021.05.18.07.38.57; Tue, 18 May 2021 07:39:23 -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=kldb5Xv3; 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 S1344950AbhEQPqI (ORCPT + 99 others); Mon, 17 May 2021 11:46:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:55470 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245718AbhEQPak (ORCPT ); Mon, 17 May 2021 11:30:40 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 92C2A60698; Mon, 17 May 2021 14:38:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621262287; bh=Y1Fi/8EmZWG4KsmdkBqPpUUPzppWQTtjsGwFkKKu/P0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kldb5Xv3KVu0eXFITy5IQk479mAezkuto6GPeG0zijB0a93nyxONZKCjhxO2UVM/N ExF4mfPgAx6GP/PDdWhZAR61PggSl4heXI/trAQq7TKAtX3zl2UYrcvndWSeVk5e+r tCYH8TLJoATzEH/xwplloHk8wEh30B10GkdD5y2E= 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.11 257/329] dax: Wake up all waiters after invalidating dax entry Date: Mon, 17 May 2021 16:02:48 +0200 Message-Id: <20210517140310.803938885@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.043055203@linuxfoundation.org> References: <20210517140302.043055203@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