Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp807864ybn; Tue, 24 Sep 2019 09:49:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqwgXsvdovskincN6eURuyzpYDF5Ee8rU/m/kNNTbDgMXp8T0aN3BYAJH2E5khXc4ign4b1N X-Received: by 2002:a17:906:bc2:: with SMTP id y2mr3471750ejg.148.1569343748290; Tue, 24 Sep 2019 09:49:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569343748; cv=none; d=google.com; s=arc-20160816; b=zCYFbEIgUEbehGZb9wejlof/83kYFlgAXqrFjH8dIkEFbe+kYSDO2WKIxP6IcSY1+7 YayxVLSorrNpzmBbXrbgLBDREB7vutkFg0QupvfWlsZNmAX/oi8TBfzyQLqAPziCbS/E MTEgBUTbE3E5qnN/vkcx3GzdGrw9Ljs3XlOzoTjjxowylhIWoswLcwir7q0zSySQGbnB 0ZEWtbteQVyiNQAoRqtPuUYASqgciFFFEKHtVSJHlH7KC+VRiXKLOMV687AbMpFxMqNR 1rVdDEI0oQFfWYacXeqGqqIKOmVZXSNbrq5cbDSljjw5j2XtHUzOX6WLyne/a+E1eul1 IsHw== 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; bh=GXIovqwqm63wtxzzyeIbAQrpQWpcAdR9JxWJf3/Rl1Y=; b=vAzimbJzoZSXWg5MYY7vS1IlaDqXtiQS/jNk9iY7amZ1cOVWaSrMSmTbsSlEqSTH3y oxx4Ys7WLduv+bpd4Hfmu5x9584Kp6phlOHg50mYOf42AdQgxPG01ia4JdMRuWnQ3/4k yYVQPlgKKAWghyZxznsYfbtxtAZg9orvazASV1bKcUqXsFB1tvWNjk7IzrKnlQts7a4t BRTmnIM/2arwnmyBD868SjynAHpE+oMTez5BjZSLe6AwbVrKtPzob2Dwi2BTaziSY8dt MCT3BLkaFDP83pjy2mweWScHuTBWRimnMVb7mEQ/uPGclr15iQKqoeBEiaWRwvjUFec+ noDw== 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id oa24si1165116ejb.41.2019.09.24.09.48.45; Tue, 24 Sep 2019 09:49:08 -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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730878AbfIWE0N (ORCPT + 99 others); Mon, 23 Sep 2019 00:26:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52494 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726536AbfIWE0L (ORCPT ); Mon, 23 Sep 2019 00:26:11 -0400 Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 22F8A883C2 for ; Mon, 23 Sep 2019 04:26:11 +0000 (UTC) Received: by mail-pl1-f197.google.com with SMTP id f8so175203plj.10 for ; Sun, 22 Sep 2019 21:26:11 -0700 (PDT) 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=GXIovqwqm63wtxzzyeIbAQrpQWpcAdR9JxWJf3/Rl1Y=; b=o5E1l53LErR3s4OIW+hvnymQBEnCooSAFgNiLGGcf6mQr/q3oKj7wrRQBDXQVmVyRB LjGOYExFLMmHSiBGLHGVM5CtdVHpN9dpCmeJEQrhyLzxOZe+iQ0HPWL9KxbZ2IqRZhYd mCVOcX6YC94ox76oanxu7d3KWr9a3+iTGOabeb4djJXfim1C+N86klX93RoZwnBtOYRC 6tH/5xfKPzMV1nJmAuetuTeKtPtB7+TEHKlKjTRM/W6DPy2YFRRzQs6+vXIrMs4uBg56 QNuhFudkhQhQVOptbDq1JzzhLFAF8ksxvBieH4pWTypVWv638fP+v3YUAe8NdQ+twSyS CLXQ== X-Gm-Message-State: APjAAAXdlZjviq3tMWnoGxLVy7lHXRHkLF+W7jNWMw5Te8kU0ZoerDrE i8BFpq0k9SsgOI2zeVKmmwIT4uf+dScy5J8o8MiEf6rlDwhGTmnPzmxW/DK4DhdskQqdn4XKVym 3LVd2iHKwBpzngGQlIEjpxBXz X-Received: by 2002:aa7:8acf:: with SMTP id b15mr24586110pfd.191.1569212770634; Sun, 22 Sep 2019 21:26:10 -0700 (PDT) X-Received: by 2002:aa7:8acf:: with SMTP id b15mr24586091pfd.191.1569212770425; Sun, 22 Sep 2019 21:26:10 -0700 (PDT) Received: from xz-x1.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id x20sm11781867pfp.120.2019.09.22.21.26.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Sep 2019 21:26:09 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: David Hildenbrand , Hugh Dickins , Maya Gokhale , Jerome Glisse , Pavel Emelyanov , Johannes Weiner , peterx@redhat.com, Martin Cracauer , Marty McFadden , Shaohua Li , Andrea Arcangeli , Mike Kravetz , Denis Plotnikov , Mike Rapoport , Linus Torvalds , Mel Gorman , "Kirill A . Shutemov" , "Dr . David Alan Gilbert" Subject: [PATCH v4 04/10] mm: Introduce FAULT_FLAG_INTERRUPTIBLE Date: Mon, 23 Sep 2019 12:25:17 +0800 Message-Id: <20190923042523.10027-5-peterx@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190923042523.10027-1-peterx@redhat.com> References: <20190923042523.10027-1-peterx@redhat.com> 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 handle_userfaultfd() is currently the only one place in the kernel page fault procedures that can respond to non-fatal userspace signals. It was trying to detect such an allowance by checking against USER & KILLABLE flags, which was "un-official". In this patch, we introduced a new flag (FAULT_FLAG_INTERRUPTIBLE) to show that the fault handler allows the fault procedure to respond even to non-fatal signals. Meanwhile, add this new flag to the default fault flags so that all the page fault handlers can benefit from the new flag. With that, replacing the userfault check to this one. Since the line is getting even longer, clean up the fault flags a bit too to ease TTY users. Although we've got a new flag and applied it, we shouldn't have any functional change with this patch so far. Suggested-by: Linus Torvalds Reviewed-by: David Hildenbrand Signed-off-by: Peter Xu --- fs/userfaultfd.c | 4 +--- include/linux/mm.h | 39 ++++++++++++++++++++++++++++----------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index fe6d804a38dc..3c55ee64bcb1 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -462,9 +462,7 @@ vm_fault_t handle_userfault(struct vm_fault *vmf, unsigned long reason) uwq.ctx = ctx; uwq.waken = false; - return_to_userland = - (vmf->flags & (FAULT_FLAG_USER|FAULT_FLAG_KILLABLE)) == - (FAULT_FLAG_USER|FAULT_FLAG_KILLABLE); + return_to_userland = vmf->flags & FAULT_FLAG_INTERRUPTIBLE; blocking_state = return_to_userland ? TASK_INTERRUPTIBLE : TASK_KILLABLE; diff --git a/include/linux/mm.h b/include/linux/mm.h index 57fb5c535f8e..53ec7abb8472 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -383,22 +383,38 @@ extern unsigned int kobjsize(const void *objp); */ extern pgprot_t protection_map[16]; -#define FAULT_FLAG_WRITE 0x01 /* Fault was a write access */ -#define FAULT_FLAG_MKWRITE 0x02 /* Fault was mkwrite of existing pte */ -#define FAULT_FLAG_ALLOW_RETRY 0x04 /* Retry fault if blocking */ -#define FAULT_FLAG_RETRY_NOWAIT 0x08 /* Don't drop mmap_sem and wait when retrying */ -#define FAULT_FLAG_KILLABLE 0x10 /* The fault task is in SIGKILL killable region */ -#define FAULT_FLAG_TRIED 0x20 /* Second try */ -#define FAULT_FLAG_USER 0x40 /* The fault originated in userspace */ -#define FAULT_FLAG_REMOTE 0x80 /* faulting for non current tsk/mm */ -#define FAULT_FLAG_INSTRUCTION 0x100 /* The fault was during an instruction fetch */ +/** + * Fault flag definitions. + * + * @FAULT_FLAG_WRITE: Fault was a write fault. + * @FAULT_FLAG_MKWRITE: Fault was mkwrite of existing PTE. + * @FAULT_FLAG_ALLOW_RETRY: Allow to retry the fault if blocked. + * @FAULT_FLAG_RETRY_NOWAIT: Don't drop mmap_sem and wait when retrying. + * @FAULT_FLAG_KILLABLE: The fault task is in SIGKILL killable region. + * @FAULT_FLAG_TRIED: The fault has been tried once. + * @FAULT_FLAG_USER: The fault originated in userspace. + * @FAULT_FLAG_REMOTE: The fault is not for current task/mm. + * @FAULT_FLAG_INSTRUCTION: The fault was during an instruction fetch. + * @FAULT_FLAG_INTERRUPTIBLE: The fault can be interrupted by non-fatal signals. + */ +#define FAULT_FLAG_WRITE 0x01 +#define FAULT_FLAG_MKWRITE 0x02 +#define FAULT_FLAG_ALLOW_RETRY 0x04 +#define FAULT_FLAG_RETRY_NOWAIT 0x08 +#define FAULT_FLAG_KILLABLE 0x10 +#define FAULT_FLAG_TRIED 0x20 +#define FAULT_FLAG_USER 0x40 +#define FAULT_FLAG_REMOTE 0x80 +#define FAULT_FLAG_INSTRUCTION 0x100 +#define FAULT_FLAG_INTERRUPTIBLE 0x200 /* * The default fault flags that should be used by most of the * arch-specific page fault handlers. */ #define FAULT_FLAG_DEFAULT (FAULT_FLAG_ALLOW_RETRY | \ - FAULT_FLAG_KILLABLE) + FAULT_FLAG_KILLABLE | \ + FAULT_FLAG_INTERRUPTIBLE) #define FAULT_FLAG_TRACE \ { FAULT_FLAG_WRITE, "WRITE" }, \ @@ -409,7 +425,8 @@ extern pgprot_t protection_map[16]; { FAULT_FLAG_TRIED, "TRIED" }, \ { FAULT_FLAG_USER, "USER" }, \ { FAULT_FLAG_REMOTE, "REMOTE" }, \ - { FAULT_FLAG_INSTRUCTION, "INSTRUCTION" } + { FAULT_FLAG_INSTRUCTION, "INSTRUCTION" }, \ + { FAULT_FLAG_INTERRUPTIBLE, "INTERRUPTIBLE" } /* * vm_fault is filled by the the pagefault handler and passed to the vma's -- 2.21.0