From patchwork Sun Jun 9 10:08:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Khlebnikov X-Patchwork-Id: 10983567 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F11281398 for ; Sun, 9 Jun 2019 10:08:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DEEB3286AE for ; Sun, 9 Jun 2019 10:08:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D343028A29; Sun, 9 Jun 2019 10:08:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A893D286AE for ; Sun, 9 Jun 2019 10:08:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D20CA6B0006; Sun, 9 Jun 2019 06:08:55 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id CA8706B0007; Sun, 9 Jun 2019 06:08:55 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B49CD6B0008; Sun, 9 Jun 2019 06:08:55 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) by kanga.kvack.org (Postfix) with ESMTP id 556336B0006 for ; Sun, 9 Jun 2019 06:08:55 -0400 (EDT) Received: by mail-lf1-f69.google.com with SMTP id r1so1314177lfi.22 for ; Sun, 09 Jun 2019 03:08:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:subject:from:to:cc:date :message-id:in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=vE25/fE3GbSUmEmrdF2LzH942xvuS41f5y8rGOLXdnQ=; b=Sato27QTasHyDD+WOdwKQ5qbRG1E0vppMggka7LnB5aJQ6X1//9+6kvDDfK8LVgLSQ biyNOEDJxelccPF1fJRSNJgkVaJcTQAulWd4k1demPSxjbd9jxKmMyKDXvL0sg4oXk3P aarBLZ3RBPboM9Fc+gvIbjj/Dj+XqSX4DvFFoMyssoHK2QfzMc/JrfBgG2aAMh3x/zEK 1gnWAShdZ3Sxcc9fBsMNg3J20YhduhqW5cRe48DZwbKkT4pnluajhCL3morShrKYvEBP 4r+2M/lwVwow6csaj0ZXphFjOKlp3VUUjZzC3BBQJzK9/11DYEESW2p71XemeiqTdL8k xABg== X-Gm-Message-State: APjAAAW0zeZYfP+0BujHb+bJqkwb3/JMNnQY7OT2YzTODydakFG6mL6P kYAcsPhnaHSlRD3uEwSF3lAy/wZQCYoy0M6xpDUy1NufwmoPbF/WwjZEZ4ZeFzZc7b9RjRrkZpA FaPeiGOpT/5YiVX2oGwKOVr8GXdxHLigEwEvQWl2TtjG0U4aU2Rv9TjcnmAd8+KVPHw== X-Received: by 2002:a2e:8ecb:: with SMTP id e11mr8558856ljl.218.1560074934616; Sun, 09 Jun 2019 03:08:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqwXnF4rEV1bZV8Q3/qn7Sj8/Mm9O3ilEsNytr4GVWVHgC5d5Ur7iSqM0IsXC/3NyeJHqOB4 X-Received: by 2002:a2e:8ecb:: with SMTP id e11mr8558829ljl.218.1560074933887; Sun, 09 Jun 2019 03:08:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560074933; cv=none; d=google.com; s=arc-20160816; b=gBgmky3unvWMDgG5+HvFZyKs/Jx7aL9lyx/3AiwE9jCNZuDXdHuMLJN1UXYOKKwaKG g3yDF1jqevf5pqe2ZXPQO0wa8frlVrfSPzCwjCBonUj8Vuj9CKzrkmcFrdQT/HdfKbea LCqkc64d0LO2ZaS1IvIT4tgkEUU/q9dVJ9pRTv5eKrXWRmvM3sKm38XqDZk5qV2SYPia ym5lK7SoB0FtWF7s8kD1+DfTLqUuUWq+o6uw+IXm8A5r1yjw/jz7C5eKbuQZqAA+Gtcl u7X1Lo8IEr+KlUUeBkZqTxGvC4adWTWwaPOWTneXS532sH6PNrrmWrTQgHM/xw5GenC7 P5Fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:cc:to:from:subject:dkim-signature; bh=vE25/fE3GbSUmEmrdF2LzH942xvuS41f5y8rGOLXdnQ=; b=K70fowrKzVGTQmeqt6/gAGehXdqdv4uwq8+/tRFpGroBl/2DzILiu8UAPSSvwLukiI PVNetugBSPE2kqMeq3FLbPl+beTXUwuTkMYFjvdRNzYUN4lTvAhs2kTM0uheWa016GcJ G8qKl2pRZRlL4syORv5sPJFqoo1OoxNVVHpi3f3JwIl33I9i5HfcUcHiMGLNyL9i8vDJ nbhDHpYjSDG/T3LnDZu/3UwJMu6J+7mD2e6dvU+BHvl0gUnwzWfXWn3+wkHFdxz080Ch ENhRgzBsUs6VCZN5flgrNfIlkOJh/0q4CfR3aUPJzVeE74aPWtWKiJkLEtSvMNv8d5nR dfcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b=JRKbcrjI; spf=pass (google.com: domain of khlebnikov@yandex-team.ru designates 5.45.199.163 as permitted sender) smtp.mailfrom=khlebnikov@yandex-team.ru; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Received: from forwardcorp1j.mail.yandex.net (forwardcorp1j.mail.yandex.net. [5.45.199.163]) by mx.google.com with ESMTPS id a6si5981008ljj.214.2019.06.09.03.08.53 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 09 Jun 2019 03:08:53 -0700 (PDT) Received-SPF: pass (google.com: domain of khlebnikov@yandex-team.ru designates 5.45.199.163 as permitted sender) client-ip=5.45.199.163; Authentication-Results: mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b=JRKbcrjI; spf=pass (google.com: domain of khlebnikov@yandex-team.ru designates 5.45.199.163 as permitted sender) smtp.mailfrom=khlebnikov@yandex-team.ru; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Received: from mxbackcorp1g.mail.yandex.net (mxbackcorp1g.mail.yandex.net [IPv6:2a02:6b8:0:1402::301]) by forwardcorp1j.mail.yandex.net (Yandex) with ESMTP id 1AFF12E087D; Sun, 9 Jun 2019 13:08:53 +0300 (MSK) Received: from smtpcorp1o.mail.yandex.net (smtpcorp1o.mail.yandex.net [2a02:6b8:0:1a2d::30]) by mxbackcorp1g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id 13LYxQ2B9j-8pliI2hm; Sun, 09 Jun 2019 13:08:53 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1560074933; bh=vE25/fE3GbSUmEmrdF2LzH942xvuS41f5y8rGOLXdnQ=; h=In-Reply-To:Message-ID:References:Date:To:From:Subject:Cc; b=JRKbcrjIO3Qau84WEWIcAh/pGsYAjU0pBAE0iOqS7wdR0k5OSt+AWz7uKQJI4mJg6 8827ndi69XToznkB0q2AePqeqDvA/uq02G6iPx4++PVKEp0BXjJpvgdvNRgAY29Sw6 RRh4rf2ePf7A9V7TIg/fu2WM1HrJJvQgXF2H2b2Q= Authentication-Results: mxbackcorp1g.mail.yandex.net; dkim=pass header.i=@yandex-team.ru Received: from dynamic-red.dhcp.yndx.net (dynamic-red.dhcp.yndx.net [2a02:6b8:0:40c:3d25:9e27:4f75:a150]) by smtpcorp1o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id 2fhLdaNKBQ-8pYaK4tB; Sun, 09 Jun 2019 13:08:51 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) Subject: [PATCH v2 1/6] proc: use down_read_killable mmap_sem for /proc/pid/maps From: Konstantin Khlebnikov To: linux-mm@kvack.org, Andrew Morton , linux-kernel@vger.kernel.org Cc: Oleg Nesterov , Matthew Wilcox , Michal Hocko , Cyrill Gorcunov , Kirill Tkhai , Michal =?utf-8?q?Koutn=C3=BD?= , Al Viro , Roman Gushchin Date: Sun, 09 Jun 2019 13:08:51 +0300 Message-ID: <156007493160.3335.14447544314127417266.stgit@buzz> In-Reply-To: <156007465229.3335.10259979070641486905.stgit@buzz> References: <156007465229.3335.10259979070641486905.stgit@buzz> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Do not stuck forever if something wrong. Killable lock allows to cleanup stuck tasks and simplifies investigation. This function also used for /proc/pid/smaps. Signed-off-by: Konstantin Khlebnikov Reviewed-by: Roman Gushchin Reviewed-by: Cyrill Gorcunov Reviewed-by: Kirill Tkhai Acked-by: Michal Hocko --- 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 01d4eb0e6bd1..2bf210229daf 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) From patchwork Sun Jun 9 10:08:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Khlebnikov X-Patchwork-Id: 10983569 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7280D1398 for ; Sun, 9 Jun 2019 10:09:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 612A7286AE for ; Sun, 9 Jun 2019 10:09:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 551D128A29; Sun, 9 Jun 2019 10:09:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A4BE286AE for ; Sun, 9 Jun 2019 10:09:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2752D6B0008; Sun, 9 Jun 2019 06:08:58 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 13A976B000A; Sun, 9 Jun 2019 06:08:58 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ECC5E6B000C; Sun, 9 Jun 2019 06:08:57 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) by kanga.kvack.org (Postfix) with ESMTP id 810A56B0008 for ; Sun, 9 Jun 2019 06:08:57 -0400 (EDT) Received: by mail-lf1-f72.google.com with SMTP id j27so1323663lfh.4 for ; Sun, 09 Jun 2019 03:08:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:subject:from:to:cc:date :message-id:in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=Osy1W1UXrB10pyCypodBWxUh9CNrVdsLdAgKLqVDe8Q=; b=Hi+KhBtp9Op9qEa5ZGVcOfpCQ/E3IjWE3L18k1v+z/XcGfIoiJuEYkDyb2vhCqqclt rCmOWSq4SS+Uzh4OWcDZNnPnP/J5qCs3q0LqBMyoQF3oVZv1OEJBIVd3aWuyUQ+tmZ4m gcXA5qbjMn81IMraV3/6d/2dBZQutbrl2cSAq1rem6Tj+mH6CwcZUMci/eVB5P1nR++N NkwESjiasn2w/Vw7JG0D7HYfOLJBx+OJ/EWLTIvQaz8D49P0K8dGHkNFYNlHSrxbtNQQ x09GdBHgS6YcqLWyrIfDqo29M8D4U9SVzjUqB0TTp4AbME0G3QBjqhi+m62u1jyHDzU9 uPgQ== X-Gm-Message-State: APjAAAV2xXQQV6WIKwHhF2f5y6QgrMKFtJLONLw742MyGUfFR4SdVPpK WbQdfRDmEyr1FcbGBhkRTc1cULHFcY8Ngrl9/FXB7rHgVijKQTiRwr5VEIv4CKODt4VLer3EBoI FGdsPNXG9m09Plzu0oa9WYy1lMkDwU+oRBMwg+ZOkrBSNfjwu9fiSROB15cs5r2pbzQ== X-Received: by 2002:a2e:9919:: with SMTP id v25mr28605877lji.191.1560074936996; Sun, 09 Jun 2019 03:08:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqziODp980qQ/E2n4CXxCuhUmLtdKRKFx/fG4Ivx32z1nIPnQft1rdcWcgOc0HSmh7pAv/Ps X-Received: by 2002:a2e:9919:: with SMTP id v25mr28605851lji.191.1560074936236; Sun, 09 Jun 2019 03:08:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560074936; cv=none; d=google.com; s=arc-20160816; b=rFhs9Msw4B/nVF21kJW2vCCdLoBEqzRcJahLnq+Y5cnRrj1ET+A20febwFZCMCNlHj DIAn+FjuuhPOcwzRkekYsYIuNIl8Gic9ldiJq7+d/deBQ8GxRpTSNILI300abXq+X1JP Xq/jrG3YsFDSYWa8MMSN2qYdqYI8fojM1j2SX9yv39HRf8YfufVr9YJ3ojuntB9XuScB yWpaxG+qpez0QGVrxQsj1YVz9G69zmhvWhd4uHp4w1R9H1HHbT6WjsGh458VXUd6k/1q sT4jBL7i2rtf1FzT8+hbU6pYukO1Jil1MK2oK7JCCQe5PIauZjzMVlk0LXESZWkChMI3 /Jtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:cc:to:from:subject:dkim-signature; bh=Osy1W1UXrB10pyCypodBWxUh9CNrVdsLdAgKLqVDe8Q=; b=YMVpouS2QzGLN1aFuQogO3NHoD1cB0bzl1iKSIijOh3aB/a5IfYHwidNMI5Z9FieMb Tmm10XzxGssfJsUhH+6QeFSkz+wkJfheHaUKqgx0ETY+/4Oi7lrH49MUrCsT+8mtlq6i 5Fs9AViQk1zyZu+m3pfvJ1/ilj9Uam8Rr+4h3J1JDiQHrQve177vet+sCgrFxttHp+UI llkWC14wlEb/yCy1QXOZ0Euig/UK0KhaH31vtLOvYsBMz67mjjtzq+1uaiRglQ6TvBGn 7lnXlkJ0jlWM37PFjrL45ImJF7TGlYQtvPRYEiAVgD2wa+zmw8MTXV+Vdut/COnUOgqK idzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b=pqKvjzXt; spf=pass (google.com: domain of khlebnikov@yandex-team.ru designates 5.45.199.163 as permitted sender) smtp.mailfrom=khlebnikov@yandex-team.ru; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Received: from forwardcorp1j.mail.yandex.net (forwardcorp1j.mail.yandex.net. [5.45.199.163]) by mx.google.com with ESMTPS id t68si6625317lff.66.2019.06.09.03.08.56 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 09 Jun 2019 03:08:56 -0700 (PDT) Received-SPF: pass (google.com: domain of khlebnikov@yandex-team.ru designates 5.45.199.163 as permitted sender) client-ip=5.45.199.163; Authentication-Results: mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b=pqKvjzXt; spf=pass (google.com: domain of khlebnikov@yandex-team.ru designates 5.45.199.163 as permitted sender) smtp.mailfrom=khlebnikov@yandex-team.ru; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Received: from mxbackcorp1o.mail.yandex.net (mxbackcorp1o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::301]) by forwardcorp1j.mail.yandex.net (Yandex) with ESMTP id 461142E0AC3; Sun, 9 Jun 2019 13:08:55 +0300 (MSK) Received: from smtpcorp1p.mail.yandex.net (smtpcorp1p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:10]) by mxbackcorp1o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id ZSzqn1Ame6-8so4F2el; Sun, 09 Jun 2019 13:08:55 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1560074935; bh=Osy1W1UXrB10pyCypodBWxUh9CNrVdsLdAgKLqVDe8Q=; h=In-Reply-To:Message-ID:References:Date:To:From:Subject:Cc; b=pqKvjzXtUBzAVSiDKLbZCOSS0t9ehWEZtZgDrRcDhRw3G6lZWgub6Zjydb5S4yDbp Y87xvNUR9I4izI0As/UKXeINdYRzMYShRSbiWoSq5onG4qSdj8aplmkyAH+PrEzyrS Bldyua8BJ063+uyN4eyxD7D8yN7XWfiVpmf6hmEg= Authentication-Results: mxbackcorp1o.mail.yandex.net; dkim=pass header.i=@yandex-team.ru Received: from dynamic-red.dhcp.yndx.net (dynamic-red.dhcp.yndx.net [2a02:6b8:0:40c:3d25:9e27:4f75:a150]) by smtpcorp1p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id eNXLUmhNGx-8sga6Q9F; Sun, 09 Jun 2019 13:08:54 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) Subject: [PATCH v2 2/6] proc: use down_read_killable mmap_sem for /proc/pid/smaps_rollup From: Konstantin Khlebnikov To: linux-mm@kvack.org, Andrew Morton , linux-kernel@vger.kernel.org Cc: Oleg Nesterov , Matthew Wilcox , Michal Hocko , Cyrill Gorcunov , Kirill Tkhai , Michal =?utf-8?q?Koutn=C3=BD?= , Al Viro , Roman Gushchin Date: Sun, 09 Jun 2019 13:08:54 +0300 Message-ID: <156007493429.3335.14666825072272692455.stgit@buzz> In-Reply-To: <156007465229.3335.10259979070641486905.stgit@buzz> References: <156007465229.3335.10259979070641486905.stgit@buzz> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Do not stuck forever if something wrong. Killable lock allows to cleanup stuck tasks and simplifies investigation. Signed-off-by: Konstantin Khlebnikov Reviewed-by: Roman Gushchin Reviewed-by: Cyrill Gorcunov Reviewed-by: Kirill Tkhai Acked-by: Michal Hocko --- fs/proc/task_mmu.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 2bf210229daf..781879a91e3b 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -832,7 +832,10 @@ static int show_smaps_rollup(struct seq_file *m, void *v) memset(&mss, 0, sizeof(mss)); - down_read(&mm->mmap_sem); + ret = down_read_killable(&mm->mmap_sem); + if (ret) + goto out_put_mm; + hold_task_mempolicy(priv); for (vma = priv->mm->mmap; vma; vma = vma->vm_next) { @@ -849,8 +852,9 @@ static int show_smaps_rollup(struct seq_file *m, void *v) release_task_mempolicy(priv); up_read(&mm->mmap_sem); - mmput(mm); +out_put_mm: + mmput(mm); out_put_task: put_task_struct(priv->task); priv->task = NULL; From patchwork Sun Jun 9 10:08:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Khlebnikov X-Patchwork-Id: 10983571 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0EA0492A for ; Sun, 9 Jun 2019 10:09:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F1AFE286AE for ; Sun, 9 Jun 2019 10:09:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E5EB928A29; Sun, 9 Jun 2019 10:09:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 80382286AE for ; Sun, 9 Jun 2019 10:09:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6917F6B000C; Sun, 9 Jun 2019 06:08:59 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 643306B000D; Sun, 9 Jun 2019 06:08:59 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4BCD36B0010; Sun, 9 Jun 2019 06:08:59 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-lf1-f70.google.com (mail-lf1-f70.google.com [209.85.167.70]) by kanga.kvack.org (Postfix) with ESMTP id D45226B000C for ; Sun, 9 Jun 2019 06:08:58 -0400 (EDT) Received: by mail-lf1-f70.google.com with SMTP id e143so1324013lfd.9 for ; Sun, 09 Jun 2019 03:08:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:subject:from:to:cc:date :message-id:in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=3rk+4uRwl46CAyP7ka3QhboNqPwEZHBXTQqkcXWKDZU=; b=crnvJNtABozoIgAIZ6neJ1P7kWVFL4ixX8r9stRv5bkJEX5NZ+Qu7nhgoEV5sX3/IW tuZDbYxzEkywqg0Nz08jvDH52t4PFAGDJod4dGXIPqkZc9lsv++zc3x/olTMfn+iO800 EqBAS4yIawJ/xPfzuevklA+fw0otoOyaGgI/AYIXpl3KFvkpBB90f4WHyg+VRYELRsZO qOv+UlfvbHJAC/+LQ2v1LrderZls3z1zuufjhj7od1Rtym+lAI5x9kvikMZnP0c6qmob s7MlfE+Dq78rZ4WlI92neV9YmljT9hxhi8JwoNE2bzVbHblRrOA6NvBsCP5xiF9Er5pU YCVw== X-Gm-Message-State: APjAAAWaPPuO5P+F+gI80Fhp52/zx8gNeaN3AS590ahn6mHKpb09wyaU mnIe7JfONyfGXSQ0kBqFdM+1KySMOs5C1XbpmIEGt4HkVc23MrPpeZRUNTpt4LgGnL7ONuX7Aqo PyRtXdb4uChY0x4zv9quggmT+JWry8HfOEDAo7ktg6n+FTa1i49sgnVDWtsjsu/ioVg== X-Received: by 2002:ac2:546a:: with SMTP id e10mr31932564lfn.75.1560074938261; Sun, 09 Jun 2019 03:08:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqySnvdJD47onbR35uHKXAsdpD/7G7aebCow9GGY9v5KAVIInX7LtgxMAh4JzvdwrGMeGxkP X-Received: by 2002:ac2:546a:: with SMTP id e10mr31932545lfn.75.1560074937487; Sun, 09 Jun 2019 03:08:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560074937; cv=none; d=google.com; s=arc-20160816; b=eTNnJKYsbnkTTc8w5nGdtMkhwxVOb1kIWQ5Lvv9vcgtZFFsa7+j0yz3sJwkQ6ol9dv gF6REnulglKXZDFB5cOFzQH7rlanVr+a/Uj29LzTBH3H8O99tgNNeY3IGyds9AvRHyNG IXnpuWMxB7ZBwpYfqb77lysD6AJpOQCejBkooO70xTvJYLj8jE+LJcZCIjZlNPGXFjJm pw2rQ0rArf3IxpQIQImKTgCLyU/A/Sb1+pq7Bu6mPtWY8ySIqJbqTJI64XHqjTKS9Pac 7HDMloeqUslo9y4GA3Lnw45fpdFyEjlPm0hJfaNrudH/qNUVLnyYbFjEe675oWyXguwm GPyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:cc:to:from:subject:dkim-signature; bh=3rk+4uRwl46CAyP7ka3QhboNqPwEZHBXTQqkcXWKDZU=; b=kaqRcqnQd1cq2taVoet16DdaSO5egegWLTD1yLjTPdmaxPwR8/XW4Wb9FdxoWtyVhX e4tgWMLWpxoDMd0OuwDHr5+/4TFbt4yRJ1pJdqnO+FYQCNR/aBXRfIvUZeQcInxm+fY9 GW9U4Wf0D0E6VE9+nDD3XtOoOFYlqFBrXkY2qvfE6xRFDMvsYr5o5yFFkxBSWSNWvX1z 5PNfLDfx5qB9kmwxGv5O+J6H97dDgdCT4EZHZJXFSHIEdNXJ+P/X4Ys536IDmXPl0eYd jGTkAQihG8J2eYSXXcJGbDK6+kc/DHig56L1h+atPTEz6xAQArk5r1F2l+VduOzP0bw1 lYTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b=HEBN1BfE; spf=pass (google.com: domain of khlebnikov@yandex-team.ru designates 5.45.199.163 as permitted sender) smtp.mailfrom=khlebnikov@yandex-team.ru; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Received: from forwardcorp1j.mail.yandex.net (forwardcorp1j.mail.yandex.net. [5.45.199.163]) by mx.google.com with ESMTPS id c6si5740128lfk.24.2019.06.09.03.08.57 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 09 Jun 2019 03:08:57 -0700 (PDT) Received-SPF: pass (google.com: domain of khlebnikov@yandex-team.ru designates 5.45.199.163 as permitted sender) client-ip=5.45.199.163; Authentication-Results: mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b=HEBN1BfE; spf=pass (google.com: domain of khlebnikov@yandex-team.ru designates 5.45.199.163 as permitted sender) smtp.mailfrom=khlebnikov@yandex-team.ru; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Received: from mxbackcorp2j.mail.yandex.net (mxbackcorp2j.mail.yandex.net [IPv6:2a02:6b8:0:1619::119]) by forwardcorp1j.mail.yandex.net (Yandex) with ESMTP id 265F52E097B; Sun, 9 Jun 2019 13:08:57 +0300 (MSK) Received: from smtpcorp1o.mail.yandex.net (smtpcorp1o.mail.yandex.net [2a02:6b8:0:1a2d::30]) by mxbackcorp2j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id pNBtwZTYyg-8udqp0pt; Sun, 09 Jun 2019 13:08:57 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1560074937; bh=3rk+4uRwl46CAyP7ka3QhboNqPwEZHBXTQqkcXWKDZU=; h=In-Reply-To:Message-ID:References:Date:To:From:Subject:Cc; b=HEBN1BfECtA+NWOl1NyhYjybz8lV9L5DriON81fOTee7qLzo9B1x324RjmVk79R1d EPwmvCOgjHYCRKWT83RsO0l/Q9io6+Tangbs3bDwNXlFGnRXGUalmBWJ7ENrOSa5Rs E5y5f08BToJC0UDl/kAKm5SjyMhHRX/j+Ms+1QrE= Authentication-Results: mxbackcorp2j.mail.yandex.net; dkim=pass header.i=@yandex-team.ru Received: from dynamic-red.dhcp.yndx.net (dynamic-red.dhcp.yndx.net [2a02:6b8:0:40c:3d25:9e27:4f75:a150]) by smtpcorp1o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id Qx30l6oFjQ-8uYGIqxH; Sun, 09 Jun 2019 13:08:56 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) Subject: [PATCH v2 3/6] proc: use down_read_killable mmap_sem for /proc/pid/pagemap From: Konstantin Khlebnikov To: linux-mm@kvack.org, Andrew Morton , linux-kernel@vger.kernel.org Cc: Oleg Nesterov , Matthew Wilcox , Michal Hocko , Cyrill Gorcunov , Kirill Tkhai , Michal =?utf-8?q?Koutn=C3=BD?= , Al Viro , Roman Gushchin Date: Sun, 09 Jun 2019 13:08:56 +0300 Message-ID: <156007493638.3335.4872164955523928492.stgit@buzz> In-Reply-To: <156007465229.3335.10259979070641486905.stgit@buzz> References: <156007465229.3335.10259979070641486905.stgit@buzz> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Do not stuck forever if something wrong. Killable lock allows to cleanup stuck tasks and simplifies investigation. Signed-off-by: Konstantin Khlebnikov Reviewed-by: Roman Gushchin Reviewed-by: Cyrill Gorcunov Reviewed-by: Kirill Tkhai Acked-by: Michal Hocko --- fs/proc/task_mmu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 781879a91e3b..78bed6adc62d 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -1547,7 +1547,9 @@ static ssize_t pagemap_read(struct file *file, char __user *buf, /* overflow ? */ if (end < start_vaddr || end > end_vaddr) end = end_vaddr; - down_read(&mm->mmap_sem); + ret = down_read_killable(&mm->mmap_sem); + if (ret) + goto out_free; ret = walk_page_range(start_vaddr, end, &pagemap_walk); up_read(&mm->mmap_sem); start_vaddr = end; From patchwork Sun Jun 9 10:08:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Khlebnikov X-Patchwork-Id: 10983573 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B665C92A for ; Sun, 9 Jun 2019 10:09:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A590B286AE for ; Sun, 9 Jun 2019 10:09:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 99A7F28A29; Sun, 9 Jun 2019 10:09:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D26F286AE for ; Sun, 9 Jun 2019 10:09:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AAF246B0010; Sun, 9 Jun 2019 06:09:01 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A37E36B0266; Sun, 9 Jun 2019 06:09:01 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 904FF6B0269; Sun, 9 Jun 2019 06:09:01 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-lf1-f71.google.com (mail-lf1-f71.google.com [209.85.167.71]) by kanga.kvack.org (Postfix) with ESMTP id 21C306B0010 for ; Sun, 9 Jun 2019 06:09:01 -0400 (EDT) Received: by mail-lf1-f71.google.com with SMTP id r1so1314199lfi.22 for ; Sun, 09 Jun 2019 03:09:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:subject:from:to:cc:date :message-id:in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=5oPoVSty0sBJvPoO4vjO+ps4MIrwZ8U/WIc8bNJraZs=; b=RInnCwYU5r82AyLmK3rkx/AAFW/u1dW9UU7UlZArES5ZS6FLgwfqrRD2Uuo97Hc5lZ M7vZ+BshiHZmDwTCSxCORBfoSlpSi/ydD3HOj4dx+UaIA1uccbFgwK/mQtrTcX4wFTgi onoWSpd5IWe6888Zfh1QPJ1VXsQAWckjMKW282bP+WAyZgp7rKgGK5hdqEcDhLRItnoK XM9AFg9nOFx7dKzPOWOJ7ybXxPs+EGsHr8vK8INGVXTB8r13yKGcHLNsMKs97AnmHP1B n8bahjuUCFXLFN7PV/Rm+3GJE2AXN0dQZkCN/T6/9FmCA0YNqPMG3wqktAWsRE/TPNMc IucA== X-Gm-Message-State: APjAAAWckOFY8pU7T4uQAZgGMrPNG9VoLjhB0TQiKgSljYB0iYggtlsP aWdHejQEBOylPS1A7cqT34pvjYPqwfGOulPR5TlAsN4YVpRU31LZzZ6WeDar315gyQdmJYkVkCv NMtMxdXHIlZNDlgkAuu3DJlS9gJ6rgmBMUaDgQzkdzK6TYGUFGLwa9dThd/6K1g8r4Q== X-Received: by 2002:a2e:81c4:: with SMTP id s4mr21314327ljg.182.1560074940539; Sun, 09 Jun 2019 03:09:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqxLWoEiaJV4+hGTQEYGyCGqInPbfCAr8GQIgIgc4WnTahiHN4fUBRdW1+AATPxbr/jhgP/c X-Received: by 2002:a2e:81c4:: with SMTP id s4mr21314291ljg.182.1560074939626; Sun, 09 Jun 2019 03:08:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560074939; cv=none; d=google.com; s=arc-20160816; b=eYcmJZZwxxGNdVVgf5fqG09Tc4TJoTCwwa9CdJVZvHFUhGxdMt5eb9ZUAbAhOLPD/1 mLMLKqfTPsTIwYI0qRarViCIF3If4nSPXfA2+u78dV+sDif7qERnvcm1RKujgC5CcpAy bwy2nBbvSFK7JpNEx12q/0R0HlJiwbuPEuxkaWOLhPkWCxssUy9T3uucQwxHmWnW18tO gLQOwt9JQRzvy+5qDpLsdwruufNNk8+HVpD9gBlDVfD6aV6iJYYQJrLmaH9eVTMz6Lib cuvvYZGfi/e8nUbWxMrES/jMgc2QhxugLYWCTo9TYnlSNbO22ooDR5P7sE2nw2O8En60 FT9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:cc:to:from:subject:dkim-signature; bh=5oPoVSty0sBJvPoO4vjO+ps4MIrwZ8U/WIc8bNJraZs=; b=b9umhttai8WOi6k8jClfjvI/28GQs3njs2pTXc5iY43z4+/n2CUT5vJEd8moAwQcod HiY3AYXEZm8w+uNEYVrPHIdCekqkDvGuQcudFxKPzpj5+J0ICGNNX2JJNCmfrjdDvgox Cq8bJH3qt2pw0O2aPW+rSTYY9lBGVvt1pzc6eHcQcqp96qXYu6qFEkATbVgz/2qa56D0 pS3yMMILKr/TTmsZPPo12XaFgBWbr3WKVD4/mrQ1Rt9mjfsAK+gt0qdvCaVifXNQaXE5 ssSsSq41nl/zcP+L4ERkKQ6AppecAXxDCWEP4hO28RJpeSiwImDa09uo4vL9Lsp2k2y6 K8jQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b=bl8dIOKj; spf=pass (google.com: domain of khlebnikov@yandex-team.ru designates 2a02:6b8:0:1a2d::193 as permitted sender) smtp.mailfrom=khlebnikov@yandex-team.ru; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Received: from forwardcorp1o.mail.yandex.net (forwardcorp1o.mail.yandex.net. [2a02:6b8:0:1a2d::193]) by mx.google.com with ESMTPS id h24si6033050ljk.98.2019.06.09.03.08.59 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 09 Jun 2019 03:08:59 -0700 (PDT) Received-SPF: pass (google.com: domain of khlebnikov@yandex-team.ru designates 2a02:6b8:0:1a2d::193 as permitted sender) client-ip=2a02:6b8:0:1a2d::193; Authentication-Results: mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b=bl8dIOKj; spf=pass (google.com: domain of khlebnikov@yandex-team.ru designates 2a02:6b8:0:1a2d::193 as permitted sender) smtp.mailfrom=khlebnikov@yandex-team.ru; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Received: from mxbackcorp1o.mail.yandex.net (mxbackcorp1o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::301]) by forwardcorp1o.mail.yandex.net (Yandex) with ESMTP id D53742E097D; Sun, 9 Jun 2019 13:08:58 +0300 (MSK) Received: from smtpcorp1j.mail.yandex.net (smtpcorp1j.mail.yandex.net [2a02:6b8:0:1619::137]) by mxbackcorp1o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id aqxL9ERVQN-8wo4pCl9; Sun, 09 Jun 2019 13:08:58 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1560074938; bh=5oPoVSty0sBJvPoO4vjO+ps4MIrwZ8U/WIc8bNJraZs=; h=In-Reply-To:Message-ID:References:Date:To:From:Subject:Cc; b=bl8dIOKjahwvfOSIMeuXLJZ3DGuX1mY6urGZHD7TNwpHIYw/EZtMJRInwuXfRDpaP KaGwlhJdz94/rIAPtPcXo1usMXoEfqZ8CJRTWILKXsK+PMAp4WbdDKBo3NPiGG/Pmv I2Fr92CzQXy5SPCtr6oJDxF+RkbyZMinoo/7lDuo= Authentication-Results: mxbackcorp1o.mail.yandex.net; dkim=pass header.i=@yandex-team.ru Received: from dynamic-red.dhcp.yndx.net (dynamic-red.dhcp.yndx.net [2a02:6b8:0:40c:3d25:9e27:4f75:a150]) by smtpcorp1j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id QIBPtRbp96-8weawET3; Sun, 09 Jun 2019 13:08:58 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) Subject: [PATCH v2 4/6] proc: use down_read_killable mmap_sem for /proc/pid/clear_refs From: Konstantin Khlebnikov To: linux-mm@kvack.org, Andrew Morton , linux-kernel@vger.kernel.org Cc: Oleg Nesterov , Matthew Wilcox , Michal Hocko , Cyrill Gorcunov , Kirill Tkhai , Michal =?utf-8?q?Koutn=C3=BD?= , Al Viro , Roman Gushchin Date: Sun, 09 Jun 2019 13:08:58 +0300 Message-ID: <156007493826.3335.5424884725467456239.stgit@buzz> In-Reply-To: <156007465229.3335.10259979070641486905.stgit@buzz> References: <156007465229.3335.10259979070641486905.stgit@buzz> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Do not stuck forever if something wrong. Killable lock allows to cleanup stuck tasks and simplifies investigation. Replace the only unkillable mmap_sem lock in clear_refs_write. Signed-off-by: Konstantin Khlebnikov Reviewed-by: Roman Gushchin Reviewed-by: Cyrill Gorcunov Reviewed-by: Kirill Tkhai Acked-by: Michal Hocko --- 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 78bed6adc62d..7f84d1477b5b 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -1140,7 +1140,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) { From patchwork Sun Jun 9 10:09:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Khlebnikov X-Patchwork-Id: 10983575 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 76F7F1398 for ; Sun, 9 Jun 2019 10:09:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 64CF4286AE for ; Sun, 9 Jun 2019 10:09:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 586E528A29; Sun, 9 Jun 2019 10:09:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD4AB286AE for ; Sun, 9 Jun 2019 10:09:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 531016B0266; Sun, 9 Jun 2019 06:09:03 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4E3506B0269; Sun, 9 Jun 2019 06:09:03 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 382DC6B026A; Sun, 9 Jun 2019 06:09:03 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-lj1-f198.google.com (mail-lj1-f198.google.com [209.85.208.198]) by kanga.kvack.org (Postfix) with ESMTP id C80306B0266 for ; Sun, 9 Jun 2019 06:09:02 -0400 (EDT) Received: by mail-lj1-f198.google.com with SMTP id p3so351297ljp.8 for ; Sun, 09 Jun 2019 03:09:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:subject:from:to:cc:date :message-id:in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=HTswKNZVinWlaXTKPwYUewNcuthjMB5ThiabC8k2HqI=; b=bSeyOSFBGnXJ40hzkCvFcpWYZ0ZnG9YPVxz1lSjs39Cg2GSKV4tHwg8J9bzovKcVn7 ePwQegCQIYHYE0MH494fJZmXpIPgwsAMdOcWunLcK2w9bDXG2FfZtEi9Jh+YjEJazRPv qv5VfsM1YbNK8D+0IBpa3i6px18O6RD9PyN2ioc9XUSZNqUFFHzkySYurjnhuUotXP08 IRcsV4DekNqKvD3pyBt1QKZRJ2lXNjNGqK8tMOV44gxsgqD27hrcqvnNi4dfgzfXd6VO RKJsSgZS1Wcc1RAHNUdnrDfJEoN731B1q0Pxb8niqLcpLa8pfb6KN4qcsBWUB+4TvlXK zZ6g== X-Gm-Message-State: APjAAAW7+eDoRipTMo+pdkkDQ/fIAWYYutltKSAEF/pkhLOwedSRzEl1 /Hlpa3/MlyofKf4ADCzzwc670+YJ74tabW0DxMh/PBkaB4cHtSMegOElr9TQqWcF1ToIuV5YXdL m7HC9QTuSgOrvpPePl9Mdx1kEwohTUFQIxT0ckBtiZi15RhoRoc8e9HpDlhsLAG0pDQ== X-Received: by 2002:a2e:301a:: with SMTP id w26mr23037911ljw.76.1560074942200; Sun, 09 Jun 2019 03:09:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqy8BnsF0d7PQOAEaKcPKKFYCm6ZrBlYvlVBeMEbyi+XGGeZh2mWvz8oq9q9Jp//SZh0pYAD X-Received: by 2002:a2e:301a:: with SMTP id w26mr23037881ljw.76.1560074941341; Sun, 09 Jun 2019 03:09:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560074941; cv=none; d=google.com; s=arc-20160816; b=gl4QXLLTu5Hq7JkH3bb7SMXH/TGemaoMJbKKh0sU9zLYJUxYgcu0BKY8ZUkdN/pxOC 0lPCz949eupYq2QQkWw0Pe32j7d/3cGkC7OJJ9DTtLRccZlGuVsgHw41fzO0o9PEwgvQ uFjOnxuMolUlRbpYV+f808JZ7NOyCnYkllqHk3P6ENFVZS+BqyMq+qOhofuwwoz+vh+2 PFqu5YEdXBl3xq/6YQFExpVNf4onpVPL+LtV94yCDQzILW9KB/rZm/r3cYV/2s1/rD4E YZBo9tJ9YbtNuChxI0VU6PVblXhBy0VrPfbl7tSW8jaKnVrtcFp4yx3+//XAKOprHddP hM/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:cc:to:from:subject:dkim-signature; bh=HTswKNZVinWlaXTKPwYUewNcuthjMB5ThiabC8k2HqI=; b=doJh5o8XmeRouOImOki4s+YEBdVAc9BCiiw95HF1aG+nwRYfavF3UacYUzIVLXpY7Y wyLiFFPtZqqmx08xuVqMOfJbqEuIxMmZ6RGJ+iTfz5dsWPNMNRNW5EUbLfE7J8y9QDn/ rfW/DlQ58qSpExPO+OBF3mBBRV2Kmhyv5dXHKdYtUoGyc5m2UMnzvP3g051PMI828Oto AqrHG8wOG7xDumLJvOYOR76hED9092Zog/Lrk3NZql7gxu3WB0dZOwEoxGB/1QN9Fjk3 oTAQlvVkjAhML69YgmCW0c2lix1zBUVPorsfkkVgzzyKHSO9ZGzjBnJ5tpGbbxkhKoO/ x70w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b=W2Lns3hn; spf=pass (google.com: domain of khlebnikov@yandex-team.ru designates 2a02:6b8:0:1a2d::193 as permitted sender) smtp.mailfrom=khlebnikov@yandex-team.ru; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Received: from forwardcorp1o.mail.yandex.net (forwardcorp1o.mail.yandex.net. [2a02:6b8:0:1a2d::193]) by mx.google.com with ESMTPS id b24si6982002lji.187.2019.06.09.03.09.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 09 Jun 2019 03:09:01 -0700 (PDT) Received-SPF: pass (google.com: domain of khlebnikov@yandex-team.ru designates 2a02:6b8:0:1a2d::193 as permitted sender) client-ip=2a02:6b8:0:1a2d::193; Authentication-Results: mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b=W2Lns3hn; spf=pass (google.com: domain of khlebnikov@yandex-team.ru designates 2a02:6b8:0:1a2d::193 as permitted sender) smtp.mailfrom=khlebnikov@yandex-team.ru; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Received: from mxbackcorp2j.mail.yandex.net (mxbackcorp2j.mail.yandex.net [IPv6:2a02:6b8:0:1619::119]) by forwardcorp1o.mail.yandex.net (Yandex) with ESMTP id DB53D2E1290; Sun, 9 Jun 2019 13:09:00 +0300 (MSK) Received: from smtpcorp1j.mail.yandex.net (smtpcorp1j.mail.yandex.net [2a02:6b8:0:1619::137]) by mxbackcorp2j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id HqcI3fm6pO-90dSh3UN; Sun, 09 Jun 2019 13:09:00 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1560074940; bh=HTswKNZVinWlaXTKPwYUewNcuthjMB5ThiabC8k2HqI=; h=In-Reply-To:Message-ID:References:Date:To:From:Subject:Cc; b=W2Lns3hnIOukrTVxWvIo0u6baEU21di7kha/doFaKrXcuN13asxGi1NnamvbmIL6R GG523ZkU7z70oZvqhg6+jHvA2776ywAPGJ7zEEGZCR2c+jbDorSPrGnQHtLbI3fTER zK40ISHd22/ieJqWF7T4KyXDg90PAatMcqztN+vk= Authentication-Results: mxbackcorp2j.mail.yandex.net; dkim=pass header.i=@yandex-team.ru Received: from dynamic-red.dhcp.yndx.net (dynamic-red.dhcp.yndx.net [2a02:6b8:0:40c:3d25:9e27:4f75:a150]) by smtpcorp1j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id 1wLN9D4DDw-90emhqeg; Sun, 09 Jun 2019 13:09:00 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) Subject: [PATCH v2 5/6] proc: use down_read_killable mmap_sem for /proc/pid/map_files From: Konstantin Khlebnikov To: linux-mm@kvack.org, Andrew Morton , linux-kernel@vger.kernel.org Cc: Oleg Nesterov , Matthew Wilcox , Michal Hocko , Cyrill Gorcunov , Kirill Tkhai , Michal =?utf-8?q?Koutn=C3=BD?= , Al Viro , Roman Gushchin Date: Sun, 09 Jun 2019 13:09:00 +0300 Message-ID: <156007493995.3335.9595044802115356911.stgit@buzz> In-Reply-To: <156007465229.3335.10259979070641486905.stgit@buzz> References: <156007465229.3335.10259979070641486905.stgit@buzz> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Do not stuck forever if something wrong. Killable lock allows to cleanup stuck tasks and simplifies investigation. It seems ->d_revalidate() could return any error (except ECHILD) to abort validation and pass error as result of lookup sequence. Signed-off-by: Konstantin Khlebnikov Reviewed-by: Roman Gushchin Reviewed-by: Cyrill Gorcunov Reviewed-by: Kirill Tkhai Acked-by: Michal Hocko --- fs/proc/base.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index 9c8ca6cd3ce4..515ab29c2adf 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -1962,9 +1962,12 @@ static int map_files_d_revalidate(struct dentry *dentry, unsigned int flags) goto out; if (!dname_to_vma_addr(dentry, &vm_start, &vm_end)) { - down_read(&mm->mmap_sem); - exact_vma_exists = !!find_exact_vma(mm, vm_start, vm_end); - up_read(&mm->mmap_sem); + status = down_read_killable(&mm->mmap_sem); + if (!status) { + exact_vma_exists = !!find_exact_vma(mm, vm_start, + vm_end); + up_read(&mm->mmap_sem); + } } mmput(mm); @@ -2010,8 +2013,11 @@ static int map_files_get_link(struct dentry *dentry, struct path *path) if (rc) goto out_mmput; + rc = down_read_killable(&mm->mmap_sem); + if (rc) + goto out_mmput; + rc = -ENOENT; - down_read(&mm->mmap_sem); vma = find_exact_vma(mm, vm_start, vm_end); if (vma && vma->vm_file) { *path = vma->vm_file->f_path; @@ -2107,7 +2113,10 @@ static struct dentry *proc_map_files_lookup(struct inode *dir, if (!mm) goto out_put_task; - down_read(&mm->mmap_sem); + result = ERR_PTR(-EINTR); + if (down_read_killable(&mm->mmap_sem)) + goto out_put_mm; + vma = find_exact_vma(mm, vm_start, vm_end); if (!vma) goto out_no_vma; @@ -2118,6 +2127,7 @@ static struct dentry *proc_map_files_lookup(struct inode *dir, out_no_vma: up_read(&mm->mmap_sem); +out_put_mm: mmput(mm); out_put_task: put_task_struct(task); @@ -2160,7 +2170,12 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx) mm = get_task_mm(task); if (!mm) goto out_put_task; - down_read(&mm->mmap_sem); + + ret = down_read_killable(&mm->mmap_sem); + if (ret) { + mmput(mm); + goto out_put_task; + } nr_files = 0; From patchwork Sun Jun 9 10:09:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konstantin Khlebnikov X-Patchwork-Id: 10983577 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E81651398 for ; Sun, 9 Jun 2019 10:09:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D7D38286AE for ; Sun, 9 Jun 2019 10:09:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CBB9B28A29; Sun, 9 Jun 2019 10:09:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F835286AE for ; Sun, 9 Jun 2019 10:09:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1887B6B026A; Sun, 9 Jun 2019 06:09:05 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1158E6B026B; Sun, 9 Jun 2019 06:09:04 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE1DB6B026C; Sun, 9 Jun 2019 06:09:04 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-lf1-f70.google.com (mail-lf1-f70.google.com [209.85.167.70]) by kanga.kvack.org (Postfix) with ESMTP id 78BA36B026A for ; Sun, 9 Jun 2019 06:09:04 -0400 (EDT) Received: by mail-lf1-f70.google.com with SMTP id d18so1317314lfn.11 for ; Sun, 09 Jun 2019 03:09:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:subject:from:to:cc:date :message-id:in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=JjGSbXYSmI2Txw4mQvoTR75+oGXHH64lCXqV4geoUls=; b=lNA000W+TcIPZbXwpEFqFgiPp0t3i+GyjKmIfotPlPGtbpKfCbite2znOBqM4WEeOu 0Jfd/liJ3YFDx3UUbvpS8RQ1soxOGfLKVrMmy4BkYfIaSHfi9W/Wx6KplTKXBNJwz57B ToXPnu7ottRaHCWvNnPc1+L46EvPieSZmhNmjpbnPsgzMmvrNF9XIt25AB2rZAd0uZ// eDykDsWNn8OqPhtMr4xPILqe2ouN0+l9SJcWQXYLRwE0Oxv89JJwwiTTbvf8BIS9aaxN ZHo5cu3sA22LDeNq9sQoMEKqqUPFaWqRbuCc7oHPfduXaHTM2dCedCRBW3ibNOt43D+7 fYCg== X-Gm-Message-State: APjAAAV2GfWRhwZF1pfFyCFyJg87iKjt8RjjHksLmpAHFI1z/j5BifL1 ubU8AV9oiEWpYQ7RNIe18Gnt9f+CHA5TRb3G1mWX+FJxDN0TkFEFWhFj8wG73BtnjtKpu8piNxH HuHPUfnomvPDLV8nTz7U7i0XFL5ttem16VwjsbBb77KwWzRqFs+/xYmFI1uAAJACV4g== X-Received: by 2002:a2e:1290:: with SMTP id 16mr13821683ljs.88.1560074943939; Sun, 09 Jun 2019 03:09:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqwdGn3dA3NjRyLH3SPbKCFgiTwNe9sfsI1opLY/RIwDHO8+awFY/onct7AHIxb7xMcQDen1 X-Received: by 2002:a2e:1290:: with SMTP id 16mr13821655ljs.88.1560074943107; Sun, 09 Jun 2019 03:09:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560074943; cv=none; d=google.com; s=arc-20160816; b=iuhCkAnXiKql8MoC7uFx07eADb6Qvr1Rp0ZnHtcwRCBAFEmGfym+B/9HcOC+TuFA6G fa+rfEtQUWnS51SMyf2iGaHct0nZN5RB4rDqnfwFn80ekMYrarYzz1i8H+oamKrcrgvU zocW+DI1zi2Lsqgy8gum7truyvsxOrfYxk7He77ldFcYZRExZYQNV15ZbFfSeMTZ0Lk2 snqNd004l4YWWrPz6DYeg9ODbUf5t3BUhMD0iKE+FpZiFl9UAjs83Y8VehZ46GNP/xaD afVcg8hKw7e3f/WoMytDpI9A+moV6JQiwPQbNRv/IYV+20x6jYP7bGANg5VxIKTPCGD9 CnAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:cc:to:from:subject:dkim-signature; bh=JjGSbXYSmI2Txw4mQvoTR75+oGXHH64lCXqV4geoUls=; b=ZIq+uJNwaZQmRbHc9pcmkZ8nrt9CPmkYFd6c+59IO7m7y/HrsOeHMYZGd6XpYIp91w 656YpKpFL52f5PHoI0ILli/ILHp/9TzuuQqbZUh7Yo58NkE6vH0PEUhMJEepXtgSTErl ycPS3lpBi6iJ+hcWEJz2YVt5bDy6ttDN23l6uZQv1nQV/chTbHpY9Wbv6bqR1Fs4HyU0 PhfTh6gs9qSjzcqwxERMYigKWAlc72ybi+WLVkgDrCx5uTP/N/X8GUZvdvJ2O3SyoM/M Df/iBzgOfyvlMd26kz/p8tA2DYtIL2XfVFaqFqLVpB4i9iSMDasewmH1rHB65tH3u77v uHNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b=z05nsIep; spf=pass (google.com: domain of khlebnikov@yandex-team.ru designates 2a02:6b8:0:1a2d::193 as permitted sender) smtp.mailfrom=khlebnikov@yandex-team.ru; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Received: from forwardcorp1o.mail.yandex.net (forwardcorp1o.mail.yandex.net. [2a02:6b8:0:1a2d::193]) by mx.google.com with ESMTPS id m76si6371958lje.218.2019.06.09.03.09.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 09 Jun 2019 03:09:03 -0700 (PDT) Received-SPF: pass (google.com: domain of khlebnikov@yandex-team.ru designates 2a02:6b8:0:1a2d::193 as permitted sender) client-ip=2a02:6b8:0:1a2d::193; Authentication-Results: mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b=z05nsIep; spf=pass (google.com: domain of khlebnikov@yandex-team.ru designates 2a02:6b8:0:1a2d::193 as permitted sender) smtp.mailfrom=khlebnikov@yandex-team.ru; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Received: from mxbackcorp2j.mail.yandex.net (mxbackcorp2j.mail.yandex.net [IPv6:2a02:6b8:0:1619::119]) by forwardcorp1o.mail.yandex.net (Yandex) with ESMTP id B8BB62E128E; Sun, 9 Jun 2019 13:09:02 +0300 (MSK) Received: from smtpcorp1p.mail.yandex.net (smtpcorp1p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:10]) by mxbackcorp2j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id GPVqI98PV5-92dCP51C; Sun, 09 Jun 2019 13:09:02 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1560074942; bh=JjGSbXYSmI2Txw4mQvoTR75+oGXHH64lCXqV4geoUls=; h=In-Reply-To:Message-ID:References:Date:To:From:Subject:Cc; b=z05nsIep3y7fvuABy75loevMGYRGUtTHeQP1HW8df8+IXOW2u4oPs4rqs77tk3V1T ySkTzZ5JZMrZYc4IRni1naQVfoWdJ/CQ7/qbULv2tO3ILPiMJ0Mts/9/h9VdWHIUQC yK30fHdHJgvsU48poLX+VtrcTBd9hqYMjvZRVDaM= Authentication-Results: mxbackcorp2j.mail.yandex.net; dkim=pass header.i=@yandex-team.ru Received: from dynamic-red.dhcp.yndx.net (dynamic-red.dhcp.yndx.net [2a02:6b8:0:40c:3d25:9e27:4f75:a150]) by smtpcorp1p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id RlV9qeaXk1-92gun05E; Sun, 09 Jun 2019 13:09:02 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) Subject: [PATCH v2 6/6] mm: use down_read_killable for locking mmap_sem in access_remote_vm From: Konstantin Khlebnikov To: linux-mm@kvack.org, Andrew Morton , linux-kernel@vger.kernel.org Cc: Oleg Nesterov , Matthew Wilcox , Michal Hocko , Cyrill Gorcunov , Kirill Tkhai , Michal =?utf-8?q?Koutn=C3=BD?= , Al Viro , Roman Gushchin Date: Sun, 09 Jun 2019 13:09:02 +0300 Message-ID: <156007494202.3335.16782303099589302087.stgit@buzz> In-Reply-To: <156007465229.3335.10259979070641486905.stgit@buzz> References: <156007465229.3335.10259979070641486905.stgit@buzz> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This function is used by ptrace and proc files like /proc/pid/cmdline and /proc/pid/environ. Access_remote_vm never returns error codes, all errors are ignored and only size of successfully read data is returned. So, if current task was killed we'll simply return 0 (bytes read). Mmap_sem could be locked for a long time or forever if something wrong. Killable lock allows to cleanup stuck tasks and simplifies investigation. Signed-off-by: Konstantin Khlebnikov Reviewed-by: Michal Koutný Acked-by: Oleg Nesterov Acked-by: Michal Hocko --- mm/memory.c | 4 +++- mm/nommu.c | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index ddf20bd0c317..9a4401d21e94 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4349,7 +4349,9 @@ int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm, void *old_buf = buf; int write = gup_flags & FOLL_WRITE; - down_read(&mm->mmap_sem); + if (down_read_killable(&mm->mmap_sem)) + return 0; + /* ignore errors, just check how much was successfully transferred */ while (len) { int bytes, ret, offset; diff --git a/mm/nommu.c b/mm/nommu.c index d8c02fbe03b5..b2823519f8cd 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -1792,7 +1792,8 @@ int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm, struct vm_area_struct *vma; int write = gup_flags & FOLL_WRITE; - down_read(&mm->mmap_sem); + if (down_read_killable(&mm->mmap_sem)) + return 0; /* the access must start within one of the target process's mappings */ vma = find_vma(mm, addr);