Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp830540ybv; Thu, 20 Feb 2020 08:03:46 -0800 (PST) X-Google-Smtp-Source: APXvYqxudeylPM61gCQnaPUGKN5cK9KwZxUFKkDfpwgdXfSyVHLh0ZUcX388hnv1qfEkJnxBGxwQ X-Received: by 2002:a9d:6181:: with SMTP id g1mr25151979otk.104.1582214626097; Thu, 20 Feb 2020 08:03:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582214626; cv=none; d=google.com; s=arc-20160816; b=FlX/hpOPa4HkSLlvA07Af9wNnXo5fOswA8MczMDuivalXW7qU5MQH8y3TPX9ub71RS 0PZA8q1JOrTUE50Mr0UqE7A8xgMZxKW3QTbjQ17VZCH55x9Kz4E3jVfK4v3nlToes+Oo wFL6RP+OR+bgNL9jTvpzLoDqxxTVYlV9TQdjTdHo5E7If4Lb+hViaduadTHWZ4zM2wns qp4QPce7EmNDHUhHWCcH2TBAzM1ZkJDgqwI7hUPr8W+8SSggSUyfDBjJVIEJxJy1nJs+ 4O8361bVq0wwG2P6jXE0/RT2L+6NOGORrI1Vh5u7huNlbeHIruMOfRJ8lAQ4FKDmOHKB QB1A== 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=q5FY/Zzd2u2AdqZ3/YqXWZ85ciAIFYLeZe5XKvNHEBI=; b=Law4Byg8Ve+CNDkOC4Z4JBP25sdxh0HJnOgW6sEmmS4U+KDNiTwlKG2ZgGncc/qXCD mwCf8XhbQ8VJRfcDaQe+WKauF4OGM3TAIr443d3b5MOrhj3St0jfhX6P3U6oGcISU6QE zt4OSPj45GjvRknNesR+eCFjX0pRP67l3s5jiYszKEByurycEClZfeOkv62FRQBzNjgt p3hH/MkmN1UGvaveGrvHf/M39e3C9qnxzsJPz+PTXqNz73iW5CA3iOI2CfdeKwV82TTY AyOVtoq1oGrlWn7lgKNiSnaSuSqar1eOzH6Fb9tGBx+MNblT92xtp5S46LTDM8Bnc8MB vxag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VMsPovza; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p22si1878583otq.132.2020.02.20.08.03.25; Thu, 20 Feb 2020 08:03:46 -0800 (PST) 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=@redhat.com header.s=mimecast20190719 header.b=VMsPovza; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728787AbgBTQDE (ORCPT + 99 others); Thu, 20 Feb 2020 11:03:04 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:36534 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728428AbgBTQDD (ORCPT ); Thu, 20 Feb 2020 11:03:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582214582; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=q5FY/Zzd2u2AdqZ3/YqXWZ85ciAIFYLeZe5XKvNHEBI=; b=VMsPovzaISRD9wCO+kDY0A5ajPO5z4kfxdo78c3KRKqEzDoBhUmtK3dHiIP4y9TnlUu1ZK v7Pg+n81bd6GlrhWM3/V0DRA5uX6cwQF3cW0ERNNfWiY93G6DW868v0Y5oBUL3C/L26XDb sR1JIt4Nz+eab5kaRAaynHsgtCfro9k= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-240-DRN7CqDQMnO2cDTxRFP9AA-1; Thu, 20 Feb 2020 11:02:59 -0500 X-MC-Unique: DRN7CqDQMnO2cDTxRFP9AA-1 Received: by mail-qk1-f199.google.com with SMTP id b23so3028198qkg.17 for ; Thu, 20 Feb 2020 08:02:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=q5FY/Zzd2u2AdqZ3/YqXWZ85ciAIFYLeZe5XKvNHEBI=; b=MbWzRvI0eEUuSu6xWLzo+k0xsGdazPwFjffRcDbsfIktqtiYt1sNxHJwVzjp9kBmSy 4QafWddqjDLwbChCGwWvCj1Ui+KcWV3SxVTvK9vOSkb8xSXr40q0ZKqK8xznuLmkrXSA tQTPlZ9Gg9BkMhwwdP29NZL1OGYXafeDkaeoVX+VMfMOn0suGPoccqMRYy5u3hFT0tAZ ufiNzc6P+PDvJmgtLpcbvc12VIzDYbIfQwT6kxGCtBGrNVVQjpp/dgzEZwCwNq+o7azI 3ZoQYUyqaG23/qat6n+k9PS6MHLh4CEH1TthISBeb+6ASZTKN3KUVaCqB1ivEL1gIJmY STWQ== X-Gm-Message-State: APjAAAXqBE71yoZHtcT6q+FUzu2NKc4w4CL3WbI0HF1MHUd5qncfdv/M 8h1FptBzaCQLuoZoA5jt80+TLq6gnvmZZcOPHWRsWwDAjDj03QIOc9wgaJUI6gUxJZ8hzd21rEY Mbh1QIL+qYoTK+7XAvhoiujcn X-Received: by 2002:ac8:76d7:: with SMTP id q23mr26733648qtr.198.1582214579291; Thu, 20 Feb 2020 08:02:59 -0800 (PST) X-Received: by 2002:ac8:76d7:: with SMTP id q23mr26733627qtr.198.1582214579032; Thu, 20 Feb 2020 08:02:59 -0800 (PST) Received: from xz-x1.redhat.com ([104.156.64.75]) by smtp.gmail.com with ESMTPSA id 139sm1821617qkg.79.2020.02.20.08.02.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Feb 2020 08:02:58 -0800 (PST) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Peter Xu , Martin Cracauer , Mike Rapoport , Hugh Dickins , Jerome Glisse , "Kirill A . Shutemov" , Matthew Wilcox , Pavel Emelyanov , Brian Geffon , Maya Gokhale , Denis Plotnikov , Andrea Arcangeli , Johannes Weiner , "Dr . David Alan Gilbert" , Linus Torvalds , Mike Kravetz , Marty McFadden , David Hildenbrand , Bobby Powers , Mel Gorman Subject: [PATCH RESEND v6 15/16] mm/gup: Allow to react to fatal signals Date: Thu, 20 Feb 2020 11:02:56 -0500 Message-Id: <20200220160256.9887-1-peterx@redhat.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200220155353.8676-1-peterx@redhat.com> References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The existing gup code does not react to the fatal signals in many code paths. For example, in one retry path of gup we're still using down_read() rather than down_read_killable(). Also, when doing page faults we don't pass in FAULT_FLAG_KILLABLE as well, which means that within the faulting process we'll wait in non-killable way as well. These were spotted by Linus during the code review of some other patches. Let's allow the gup code to react to fatal signals to improve the responsiveness of threads when during gup and being killed. Signed-off-by: Peter Xu --- mm/gup.c | 12 +++++++++--- mm/hugetlb.c | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index ec2b76f44a01..3f0cb14334ac 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -648,7 +648,7 @@ static int faultin_page(struct task_struct *tsk, struct vm_area_struct *vma, if (*flags & FOLL_REMOTE) fault_flags |= FAULT_FLAG_REMOTE; if (locked) - fault_flags |= FAULT_FLAG_ALLOW_RETRY; + fault_flags |= FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE; if (*flags & FOLL_NOWAIT) fault_flags |= FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_RETRY_NOWAIT; if (*flags & FOLL_TRIED) { @@ -991,7 +991,7 @@ int fixup_user_fault(struct task_struct *tsk, struct mm_struct *mm, address = untagged_addr(address); if (unlocked) - fault_flags |= FAULT_FLAG_ALLOW_RETRY; + fault_flags |= FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE; retry: vma = find_extend_vma(mm, address); @@ -1113,7 +1113,13 @@ static __always_inline long __get_user_pages_locked(struct task_struct *tsk, break; *locked = 1; - down_read(&mm->mmap_sem); + ret = down_read_killable(&mm->mmap_sem); + if (ret) { + BUG_ON(ret > 0); + if (!pages_done) + pages_done = ret; + break; + } ret = __get_user_pages(tsk, mm, start, 1, flags | FOLL_TRIED, pages, NULL, locked); diff --git a/mm/hugetlb.c b/mm/hugetlb.c index ac9a28d51674..c342b091a7a4 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4338,7 +4338,8 @@ long follow_hugetlb_page(struct mm_struct *mm, struct vm_area_struct *vma, if (flags & FOLL_WRITE) fault_flags |= FAULT_FLAG_WRITE; if (locked) - fault_flags |= FAULT_FLAG_ALLOW_RETRY; + fault_flags |= FAULT_FLAG_ALLOW_RETRY | + FAULT_FLAG_KILLABLE; if (flags & FOLL_NOWAIT) fault_flags |= FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_RETRY_NOWAIT; -- 2.24.1