Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3102712ybi; Thu, 18 Jul 2019 21:05:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqzTj85PnmVLY0XTjgVtfsBGyKHeHm2HWxE/RNxw1YSX8/RVkKBPhemIYdRJF/m1fTULBlvn X-Received: by 2002:a63:e70f:: with SMTP id b15mr51884432pgi.152.1563509101487; Thu, 18 Jul 2019 21:05:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563509101; cv=none; d=google.com; s=arc-20160816; b=qgEP8vXqmJOXgVb9T1CyYBHAkiOzRlCI0mOImpyIxVpSwRbujBZ2QwcbQnSRPs2u5h XQgcQFeEO5I7a21xdY6zwJOHneYVOm7At/w4sBx1IQJtOhl4A+CD0Ck+zh4BB1bj/iLk HOM5HiAwOiyJvnYlqlUKJQxKTLril99M9LhLbqSQ7J5GZcZT6fxMWhTZzJbgX9Vmt/ik x1cOuhpgQ1K9C/thqzJoXL+TGnsgSoJk3lc+wT5uALVdVPSPI22EbnA/z7QQ00pyoEG5 ZUZhFBOgYg5hY+JxLzxJsJenrrV7ln8Jfdz8zu1QpDsEzYTWwW38zjdS0sZ2yp6SttQa +BAw== 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=vGJfsBytQOb9QRiPDPNKkANZ9vY+ZqVN7C+LGE1YQ/A=; b=gsl7h3WFqjRb8SIHR3h/SzBHg2XWMjPGGB5/DMrQxrvs0YzZg3A2CHvVGuxv/beYG7 aPRdQ7ksW4SXaKD0D1DtsxVmM/QOSr1ZFkJmAX1+yhAR9I+lcG91JUUKAZpjkJNuWJWt LCoPV03RabUlxTTg5u34RRfrDyylKGZT0ggSqhW9vz77ATqxzk5cBy9+eY1DIBCqJUfg 83wQdzRs8NCQ1N+lPNWKcPMw6Wr6pEelPl/bhObFhuxlAX0EF2a1bbJ+yOeA5+SHpLfC t7tEzLPCkW/Dy7/aOxCrOOD+figyre442Oqh0LMTBfAQDMrIyhtODIbsL5OKvFDmcZWu PPag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vmsPFrxL; 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 21si1539666pfo.138.2019.07.18.21.04.46; Thu, 18 Jul 2019 21:05:01 -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=vmsPFrxL; 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 S1730047AbfGSEC3 (ORCPT + 99 others); Fri, 19 Jul 2019 00:02:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:34340 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729926AbfGSEC1 (ORCPT ); Fri, 19 Jul 2019 00:02:27 -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 4115721873; Fri, 19 Jul 2019 04:02:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563508946; bh=e33K/PgkT9ertm5p1rJP9u41KB9sEAiSq5veVZpwOL8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vmsPFrxLsF8dpb0F6iGZdEG4pSi+M+a6cVwfeUOJ9aRlNv5G8c3l5y3Fzln4rX+Fk aqE5LB8kn/yujz96nFdsMIV82gm+Hki5tcjpHg2ZGU2OJih+ZSsSzLAz6pyqIS8EF6 Vkdv+Jo7YT6uMQzYqJ9iOH9X6lx+BjWoj4yc538s= 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 168/171] proc: use down_read_killable mmap_sem for /proc/pid/maps Date: Thu, 18 Jul 2019 23:56:39 -0400 Message-Id: <20190719035643.14300-168-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 8a713e7df3352b8d9392476e9cf29e4e185dac32 ] Do not remain stuck forever if something goes wrong. Using a killable lock permits cleanup of stuck tasks and simplifies investigation. This function is also used for /proc/pid/smaps. Link: http://lkml.kernel.org/r/156007493160.3335.14447544314127417266.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 | 6 +++++- fs/proc/task_nommu.c | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index abcd9513efff..7f84d1477b5b 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -166,7 +166,11 @@ static void *m_start(struct seq_file *m, loff_t *ppos) if (!mm || !mmget_not_zero(mm)) return NULL; - down_read(&mm->mmap_sem); + if (down_read_killable(&mm->mmap_sem)) { + mmput(mm); + return ERR_PTR(-EINTR); + } + hold_task_mempolicy(priv); priv->tail_vma = get_gate_vma(mm); diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c index 36bf0f2e102e..7907e6419e57 100644 --- a/fs/proc/task_nommu.c +++ b/fs/proc/task_nommu.c @@ -211,7 +211,11 @@ static void *m_start(struct seq_file *m, loff_t *pos) if (!mm || !mmget_not_zero(mm)) return NULL; - down_read(&mm->mmap_sem); + if (down_read_killable(&mm->mmap_sem)) { + mmput(mm); + return ERR_PTR(-EINTR); + } + /* start from the Nth VMA */ for (p = rb_first(&mm->mm_rb); p; p = rb_next(p)) if (n-- == 0) -- 2.20.1