Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp5443609imm; Tue, 16 Oct 2018 10:18:06 -0700 (PDT) X-Google-Smtp-Source: ACcGV60Al167hLJSe3A1lier632u+uuHs+/64DqotX/pX8QriG2L/V8taeLJhFMQ/QJDKXLCMgQE X-Received: by 2002:a63:3507:: with SMTP id c7-v6mr20776032pga.158.1539710285952; Tue, 16 Oct 2018 10:18:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539710285; cv=none; d=google.com; s=arc-20160816; b=T5OPDBk1jZAb22RJFGDsz/21A7NzophRgk5ZmCoFWOL+4LXyzv9IgIkRxjGm5klMxB QeS793IFg0tHjzIq7VpGfAYgPHdIlE9NIRstkTrp1KFAp3WunEvVJ2lb4ZLbcnjFIaX1 HeKB4fU8KHZY0ibI4W9sf6t+3oQAhL1YXzggmgn/2QEK0L2Pnb2F7iKvNTr5IHPSDQKd KypK8JsDb7b/5PbQSfBVFUjGWsHkX93dmhkZpO6LCYT21m2bgf27iGYEfxEqXBaqM5CC seMI6gy52n6ZCP9YyXKRecs77mQz9jOxtsKHFr4OdPiPQw0AY7DNnET67/yemPs/hrft TOYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=pQpCmNo03thlqH/nC8MBMBH2RGjz96JGD1IcU0ARFq0=; b=u/r4GOPkVQVnrp9mhowxYVcA3fjdJlNTJ5uS+L91jPrsgMj+9kOtw++ViDhvbc+NnJ SZjbzpE1XHvVMlVQm1Rvuhu9b6RV2IzeYh0W1HSC3GY0x3Q4QZ9TrSZpEIBhZTFwX+sE bBWp/7CNqKCvle8wF/MrONO1tlNLxf6LvtZnlw2VJJ0AUHBh54Gf7hLX2JlrGEyIIuku LGEcb0hTsBehpF+xzjxNo6vsY6vp6gRAaMXf+oDfe1HyVBBgOX0OenwUjUBVIQ9cCQJF lOW9oJA7l6vnUnfKBxxsPr1B/yGi6IxGd3JJ+PkUZekN5OGXyxlLtZaCt1fa0QzKzsYH 3yeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=OyejWFpB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g27-v6si13843384pfj.37.2018.10.16.10.17.50; Tue, 16 Oct 2018 10:18:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=OyejWFpB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729676AbeJQBHv (ORCPT + 99 others); Tue, 16 Oct 2018 21:07:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:52358 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728606AbeJQBHu (ORCPT ); Tue, 16 Oct 2018 21:07:50 -0400 Received: from localhost (ip-213-127-77-176.ip.prioritytelecom.net [213.127.77.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9FA102098A; Tue, 16 Oct 2018 17:16:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539710187; bh=sGJWfwQgKCWgJoO5oPMTZRhEEQeivGN24h4iap2Op/g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OyejWFpBQ1JtYl6Lz4XhEPidkOVBlYP5PA3DZfSlOAAJoK/aVUkR5E2LfniLd55ek wkDawr0GgDfe6VYH2ndJU1wt8LVmF2rBLzqcxtEl44OKtKAB9z3PiWFnaGBfkUr6gw ifFR0LYtfVg92Fye9/8M1gXpsjnkc5Scs8RBxz2Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ross Zwisler , Matthew Wilcox , Jan Kara , Dan Williams Subject: [PATCH 4.18 133/135] filesystem-dax: Fix dax_layout_busy_page() livelock Date: Tue, 16 Oct 2018 19:06:03 +0200 Message-Id: <20181016170524.437414404@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181016170515.447235311@linuxfoundation.org> References: <20181016170515.447235311@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dan Williams commit d7782145e1ad537df4ce74e58c50f1f732a1462d upstream. In the presence of multi-order entries the typical pagevec_lookup_entries() pattern may loop forever: while (index < end && pagevec_lookup_entries(&pvec, mapping, index, min(end - index, (pgoff_t)PAGEVEC_SIZE), indices)) { ... for (i = 0; i < pagevec_count(&pvec); i++) { index = indices[i]; ... } index++; /* BUG */ } The loop updates 'index' for each index found and then increments to the next possible page to continue the lookup. However, if the last entry in the pagevec is multi-order then the next possible page index is more than 1 page away. Fix this locally for the filesystem-dax case by checking for dax-multi-order entries. Going forward new users of multi-order entries need to be similarly careful, or we need a generic way to report the page increment in the radix iterator. Fixes: 5fac7408d828 ("mm, fs, dax: handle layout changes to pinned dax...") Cc: Cc: Ross Zwisler Cc: Matthew Wilcox Reviewed-by: Jan Kara Signed-off-by: Dan Williams Signed-off-by: Greg Kroah-Hartman --- fs/dax.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) --- a/fs/dax.c +++ b/fs/dax.c @@ -558,6 +558,8 @@ struct page *dax_layout_busy_page(struct while (index < end && pagevec_lookup_entries(&pvec, mapping, index, min(end - index, (pgoff_t)PAGEVEC_SIZE), indices)) { + pgoff_t nr_pages = 1; + for (i = 0; i < pagevec_count(&pvec); i++) { struct page *pvec_ent = pvec.pages[i]; void *entry; @@ -571,8 +573,15 @@ struct page *dax_layout_busy_page(struct xa_lock_irq(&mapping->i_pages); entry = get_unlocked_mapping_entry(mapping, index, NULL); - if (entry) + if (entry) { page = dax_busy_page(entry); + /* + * Account for multi-order entries at + * the end of the pagevec. + */ + if (i + 1 >= pagevec_count(&pvec)) + nr_pages = 1UL << dax_radix_order(entry); + } put_unlocked_mapping_entry(mapping, index, entry); xa_unlock_irq(&mapping->i_pages); if (page) @@ -580,7 +589,7 @@ struct page *dax_layout_busy_page(struct } pagevec_remove_exceptionals(&pvec); pagevec_release(&pvec); - index++; + index += nr_pages; if (page) break;