Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932911AbcJLMps (ORCPT ); Wed, 12 Oct 2016 08:45:48 -0400 Received: from mail.kernel.org ([198.145.29.136]:48864 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755204AbcJLMph (ORCPT ); Wed, 12 Oct 2016 08:45:37 -0400 From: lizf@kernel.org To: stable@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Zefan Li Subject: [PATCH 3.4 121/125] Fix incomplete backport of commit 0f792cf949a0 Date: Wed, 12 Oct 2016 20:33:57 +0800 Message-Id: <1476275641-4697-121-git-send-email-lizf@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1476275600-4626-1-git-send-email-lizf@kernel.org> References: <1476275600-4626-1-git-send-email-lizf@kernel.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1044 Lines: 41 From: Zefan Li 3.4.113-rc1 review patch. If anyone has any objections, please let me know. ------------------ Signed-off-by: Zefan Li --- mm/hugetlb.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 416cbfd..6726bfe 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2929,13 +2929,17 @@ out_page_table_lock: unlock_page(pagecache_page); put_page(pagecache_page); } - if (page != pagecache_page) - unlock_page(page); - put_page(page); - out_mutex: mutex_unlock(&hugetlb_instantiation_mutex); - + /* + * Generally it's safe to hold refcount during waiting page lock. But + * here we just wait to defer the next page fault to avoid busy loop and + * the page is not used after unlocked before returning from the current + * page fault. So we are safe from accessing freed page, even if we wait + * here without taking refcount. + */ + if (need_wait_lock) + wait_on_page_locked(page); return ret; } -- 1.9.1