Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2076960ybi; Sun, 9 Jun 2019 03:12:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqyHDGPM6SkCgcfAmDanWd4IoFwlVktdG+w04QPyPrOftYLzv6f8qWH/LmW36C7aW3bywYEv X-Received: by 2002:a17:902:d70a:: with SMTP id w10mr56228210ply.251.1560075132092; Sun, 09 Jun 2019 03:12:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560075132; cv=none; d=google.com; s=arc-20160816; b=XcZQKxY64VW4JAWKl5Rt0XjCAa5UHDleCxYeAW9ie3oHFY7HTgJchh4uYJ9LaVRZyB enV6JFL3GcU1bCZc/vzBPIxGWm6sZerAvxLlja4VDaPnja8K4HJ0Qvu1a8yVQ3FmqSlh l7vE/CYyWN1meZ50hAkLHMaQ56lwSUbzzwAlgdI195gll6XunBO5C0vabbLLx3i9anti eLbgjAptEBBVf2hpaUQf8vrGqO88hUee+JOPDjm4JcYojbFlswVRy2McuHrwuEzyDcbx TYzU9qAXT5BQPTWAISahDk7h0NvqvGLWeLf2w7beutxX9XKzteNn60S/WMwqR7CMPphf cs4g== 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:cc:to:from :subject:dkim-signature; bh=5oPoVSty0sBJvPoO4vjO+ps4MIrwZ8U/WIc8bNJraZs=; b=j0HorKhR0IvbJoFn7s7HiN2fTF+prUjWvrQyG1twKG1TJ4qsGVULOAMCV0uyF/hjEH C8fRsrOU/N2VfKwTWjDvDSfmBiIGRWaiyYjg2s+uPu9ga8AwjYd4Rg3LCqK6QqWNM9yu Nv0xbTF2qSflk72blANGfSf+VT4L8tkvsiIii4vz2x2ULPwiorEq3zdrGVJFK8u6bXve RmmMqaYULXtLSiCX9o1Ab4pUHxVDXMlR9cQjQwhaDzHkM9BhOA6W6kGZ+XEfnGojGu0e M3d7IG2s85UWkwGeXjCm3R365UP2Y2p5I6qxB5RppoM7V5Ej9gchjcuwgLGBmBX+Z8oT PkVg== 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: 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=yandex-team.ru Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b6si7073166pgq.465.2019.06.09.03.11.56; Sun, 09 Jun 2019 03:12:12 -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=@yandex-team.ru header.s=default header.b=bl8dIOKj; 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=yandex-team.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728302AbfFIKJP (ORCPT + 99 others); Sun, 9 Jun 2019 06:09:15 -0400 Received: from forwardcorp1o.mail.yandex.net ([95.108.205.193]:55212 "EHLO forwardcorp1o.mail.yandex.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728189AbfFIKJB (ORCPT ); Sun, 9 Jun 2019 06:09:01 -0400 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) {