Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1832161yba; Fri, 17 May 2019 06:13:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqyx41MqJA673uSSyWs1w27QHtvVeMMeZyDVBParxgjt608oqAeYZNOSnO04ho4qWNVNJLOB X-Received: by 2002:a62:5587:: with SMTP id j129mr39600608pfb.45.1558098799863; Fri, 17 May 2019 06:13:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558098799; cv=none; d=google.com; s=arc-20160816; b=BEFt4ih83TbY+AKnyICeu5nkQXj3HExOFoFYK8W8tXJA836knlG/agIwgaTkVgX3uR cCKhK8+jFRmvcBZsRTeGWTag3R/qB3ZaoPQHGm6kYhkwjq/ObFVP4zvXyNAsnUetwKzY BWwrWV3if8LOWgVwWVS/kiAqmBR0eWInmQ+O+E8j2J0TLN+OlHMDOShbkx/8o55P93/T Iwi0/5aanI1bKdX6cL93NQrphfSdYbw1p8xbcIrkkODEFARxxyhTTqAJgZAA1M0UJs2J oGJbt+azZw0nuYkQLfX7pyjbtfCXu6dyCCRk97aDWx/yJu5y4akQXJyzT4ZWJE5LRVSP YlFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=M2HTy9xOQmyliFETPI0RaP5AuTsQ1dyO524mMwUa/L4=; b=uC102rdKianLaeGFYXC6MEd0yH1ZrGdIqQ62GVAwuwMjG+bKuBvo3WIzMaxDX7Ouym eL3ZDwZpYdpMiLvjETkiGXtI/UBf76/faUWgnTzs6MDrc/4uQNRJZb7K2fEL+IhbTpjn judlttZ2svYvw2GsYcFftEKys1OJ7utNRku+dGhA3HgPDyFAXftN1r+TZMkO5wSISHJl zxZgFkLgy7BDoJtEp++yHi0BZjE08tqdTeVAFRGHVf1fcvUgFmcR/2bzPIj7if4RfI3u qeu6w3r3OhKA1TbTSVEfpsmeCMs39Oe/le6eXWgcS0o0frtpu2lq7LAALtHXAS53Y6wc rCuA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (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 h11si7932551pgq.170.2019.05.17.06.13.04; Fri, 17 May 2019 06:13:19 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728882AbfEQMvg (ORCPT + 99 others); Fri, 17 May 2019 08:51:36 -0400 Received: from mx2.suse.de ([195.135.220.15]:35714 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728100AbfEQMvg (ORCPT ); Fri, 17 May 2019 08:51:36 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 5E16BAF59; Fri, 17 May 2019 12:51:35 +0000 (UTC) Date: Fri, 17 May 2019 14:51:34 +0200 From: Michal Hocko To: Konstantin Khlebnikov Cc: linux-mm@kvack.org, Andrew Morton , linux-kernel@vger.kernel.org, Oleg Nesterov Subject: Re: [PATCH] mm: use down_read_killable for locking mmap_sem in access_remote_vm Message-ID: <20190517125134.GE1825@dhcp22.suse.cz> References: <155790847881.2798.7160461383704600177.stgit@buzz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <155790847881.2798.7160461383704600177.stgit@buzz> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed 15-05-19 11:21:18, Konstantin Khlebnikov wrote: > This function is used by ptrace and proc files like /proc/pid/cmdline and > /proc/pid/environ. Return 0 (bytes read) if current task is killed. Please add an explanation about why this is OK (as explained in the follow up email). > Mmap_sem could be locked for a long time or forever if something wrong. > > Signed-off-by: Konstantin Khlebnikov 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 96f1d473c89a..2e6846d09023 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -4348,7 +4348,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 b492fd1fcf9f..cad8fb34088f 100644 > --- a/mm/nommu.c > +++ b/mm/nommu.c > @@ -1791,7 +1791,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); -- Michal Hocko SUSE Labs