Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3102009ybi; Thu, 18 Jul 2019 21:04:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqwSnED6pk0ulb3eaxZF6//jB/n4S6M5bGG3TSX+ZtQ80x523ymnpIHRyJG9MBrKIl7vst1B X-Received: by 2002:a17:90a:cb81:: with SMTP id a1mr53752268pju.81.1563509053027; Thu, 18 Jul 2019 21:04:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563509053; cv=none; d=google.com; s=arc-20160816; b=vpzYyFVGArBHssKQg9ze5Y/LOURDj1A5Kk9mkrtJKtIJrmIyII/CM6BXVl7Y4aOVuu zYfqrUZf601pnd3tT8ssQ9v/rlFvrJjlTlxFPKwRVDqTHz5Xe+DZ1yaFSBaC1zfqsoxq Oh9lKmqzwVGVpCRVSy14U8ojxKTHbhIVzzRltN878Ic0H6Stp5/JaptiUCbtt8PWSfWQ g+casZl6hOfSQ+bEjgJD/o70s/f2sR/1hGImFr8wxm7ZehhzE5u4O8WfQHsM0jRTy+hl LbQQaBh7E0XWJX/t8EKAhPfqzHrPMTjzl9zV+cntLGjlCzIgo+D5XB3m7mgTWs9Pn0J/ WPcQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Z/hhNA4Qjmqlc98goUxZ4bIRxQ0f1erKoEgnxV/cr6w=; b=rs53ljHlispbwz9JFuivXlFEFNiNQwFPbOtKHM17VW+CQP50gky+cpOi4t7RnMc5T8 FvrgZk3O/Qhws7uQ0Ztnwe645CRVTmH5WRf+XF62Ix4qPX34kIUHmALG9OO6Ln8XBxF2 BSenFCtAs47zmwUxAtJsPxmn43u7JZ9QmdYmCr0gI1rOd2WU4uTnQRmVeHz3scjyP9xp a4BsAQOuRsETmNfCGthwgHGRLeQapL0Ow3aXFVJObi5RhlUnfoFU3ZOmLsMMo/6Z6x91 wMycPu1NemW/WF6fjyp6nREvsufbyYuqGWyYOoUr1fVUAWbOnb5XWSKFzZmk35xfVSf3 gSwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QdKGf8EQ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i8si363331pgs.87.2019.07.18.21.03.57; Thu, 18 Jul 2019 21:04:13 -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=QdKGf8EQ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728880AbfGSECY (ORCPT + 99 others); Fri, 19 Jul 2019 00:02:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:34248 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729926AbfGSECT (ORCPT ); Fri, 19 Jul 2019 00:02:19 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8B79421851; Fri, 19 Jul 2019 04:02:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563508938; bh=AsWeCu7Nx+RB8vYcUFehf/VOmlzRRWN98qdGTaeI180=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QdKGf8EQldXu2w+Ahhtf3gB0DSh4c19pJx3VLNrxwYDiZdsgY7+K8ruHA8J/sASpW dou3qAaNDhc8jQU3VpRNo0h+WYOn+q62gE4SQvkAXy7+9khAMIGl7rBKDg5YmOm5aO gpV/7UPvJrCN0cq48ZdA/fcFWBNfCLoRSXcH71yA= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Konstantin Khlebnikov , Roman Gushchin , Cyrill Gorcunov , Kirill Tkhai , Michal Hocko , Alexey Dobriyan , Al Viro , Matthew Wilcox , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Oleg Nesterov , Andrew Morton , Linus Torvalds , Sasha Levin , linux-fsdevel@vger.kernel.org Subject: [PATCH AUTOSEL 5.2 165/171] proc: use down_read_killable mmap_sem for /proc/pid/clear_refs Date: Thu, 18 Jul 2019 23:56:36 -0400 Message-Id: <20190719035643.14300-165-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190719035643.14300-1-sashal@kernel.org> References: <20190719035643.14300-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Konstantin Khlebnikov [ Upstream commit c46038017fbdcac627b670c9d4176f1d0c2f5fa3 ] Do not remain stuck forever if something goes wrong. Using a killable lock permits cleanup of stuck tasks and simplifies investigation. Replace the only unkillable mmap_sem lock in clear_refs_write(). Link: http://lkml.kernel.org/r/156007493826.3335.5424884725467456239.stgit@buzz Signed-off-by: Konstantin Khlebnikov Reviewed-by: Roman Gushchin Reviewed-by: Cyrill Gorcunov Reviewed-by: Kirill Tkhai Acked-by: Michal Hocko Cc: Alexey Dobriyan Cc: Al Viro Cc: Matthew Wilcox Cc: Michal Koutný Cc: Oleg Nesterov Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- fs/proc/task_mmu.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 1d9c63cd8a3c..abcd9513efff 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -1136,7 +1136,10 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf, goto out_mm; } - down_read(&mm->mmap_sem); + if (down_read_killable(&mm->mmap_sem)) { + count = -EINTR; + goto out_mm; + } tlb_gather_mmu(&tlb, mm, 0, -1); if (type == CLEAR_REFS_SOFT_DIRTY) { for (vma = mm->mmap; vma; vma = vma->vm_next) { -- 2.20.1