Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1036306ybv; Thu, 20 Feb 2020 11:54:23 -0800 (PST) X-Google-Smtp-Source: APXvYqzsaQhHgxvAcHQDOnWZD25GjB+BywrYEQFXY2Y7AWv3fgLugRrct7EifV9Gi+i2kMHTg6+J X-Received: by 2002:a05:6830:1188:: with SMTP id u8mr25096650otq.274.1582228462974; Thu, 20 Feb 2020 11:54:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582228462; cv=none; d=google.com; s=arc-20160816; b=MAgKe6By43K5WBWHeaihrbVnV516yxOn2juznIFRV9SdXjK9LZ/ect7VWaXdXZ4cQB 2hLN5vsLaZE/utACMBPt74SpII9YznwGpp2L6PotVDR/e1BieaRgLqGhcFZ9rx6Z0F9f t9xCpdVyVpqagZsAPv0N6L/qo56cEPzVi7EXVVRBrH5eMpKgN2Fo+QzWKNp74v9XsidC 7p8fZ7z8tRxkWnGa108CtTbGx73XmaLXyh1sgshTqgu5Z1Wix1nyo0HGmFx0aSBe6EsM fPtRYyW+xl4Uz8pX/okKhcPent4QG5tKvl1rBm4Sr1b7tmjr9NDIpqPxORUKVZv6fF6M AytA== 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=aCcTytOP234Bpez2/x/ttANB+L1zPQGu6RuaOR8/cjA=; b=qCOIQA49MFCzhlFoFxuYy1xAZGX7RmBWv2CS33C4q8lyDiKdXYZ397WkWDwpQD/ZGr mMKoehumb7l2WaFTwxDdzZwSdkhI8NyuWRamUnMeLAlkEqt2g1C2fKSwmq++DLQkSDpm eJ1ZKay3zWpB9iWOy1fUWZUxTiIozKDmIHznsOtp31KV4TqoW6HAcGazDSlLWWJIiB4n NsYhNwzb9IPj98ko4EJwMtNJRXlGbKkVhwIb8eUgU+L+yrhn1BK5qe7cYlvP8xLB6B7m bVySlfkhmx/72ROBB9G9Q/eRM+1ZUoPEsDwVP7hwTsxqon+GIovHT8dtsv7Z2EysfiJL K/ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="R/+g2KqP"; 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 l11si198429oth.286.2020.02.20.11.54.11; Thu, 20 Feb 2020 11:54:22 -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="R/+g2KqP"; 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 S1728929AbgBTTxz (ORCPT + 99 others); Thu, 20 Feb 2020 14:53:55 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:23065 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728556AbgBTTxz (ORCPT ); Thu, 20 Feb 2020 14:53:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582228433; 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=aCcTytOP234Bpez2/x/ttANB+L1zPQGu6RuaOR8/cjA=; b=R/+g2KqP5hVOiDlEPrdthY0zZipHrIiOT8zX8UaWWGwk/yQPN2c2kTpX0TSJd+PTAPvsS3 3ObNYlXXOxyIDbwzKMN3e1UN8fZw+HjwN3RIms5njE0snpq2U2yuVtF3AKsmWADPu6mIBl JI/Vo925y0OwOBBM5hToeYbuC94Q+Xg= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-460-eixVDyz7OtGZCB7eiNrKyQ-1; Thu, 20 Feb 2020 14:53:51 -0500 X-MC-Unique: eixVDyz7OtGZCB7eiNrKyQ-1 Received: by mail-qt1-f197.google.com with SMTP id o18so3379345qtt.19 for ; Thu, 20 Feb 2020 11:53:51 -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=aCcTytOP234Bpez2/x/ttANB+L1zPQGu6RuaOR8/cjA=; b=SmCOYl6Wa8Y7aBhc2OOcHlVHvrzWILV8qmM4MKPzgAWcJ3Q9nW8wqnw92aiVEhqc61 dr+/u1ug887K1KNuOMvMSr89UWylFIUzVIxAnvfLm5hw3Vesx5CX5LSnUC0jsqB8OfPb yZjJh0YqXiZa6PM0UV7ok6sc+BumO/I/q4fogB+YIUvmHk69M5dRlfHEM9Djjj8xlQRG Shk3QdQAx4q36X998n0oO6U8YIunuqV7cFxuFCXX5revNl5O4YDJpF+sM6nq0/SthLI8 PPk3R+tiWDPfulVmYYABqE0/6QV0KPxPWRMx8CPqs+XYrvNp+cVj9QCwZrGu168HBhyD 1brQ== X-Gm-Message-State: APjAAAUeVhwq2mds2Fm5loxWgjdGJiyHWxIYOcc7ylRunIHPPRwqUIDl SxeV/ws8PgG56WTEBBB0gLcemNeDMInsnGaPBHs2jYVwrWN9wtc7rJzTg/Ycpw3AtffaharEyLk 6u0gmOwDcGmeRqaFtwEyoafU5 X-Received: by 2002:a0c:eacb:: with SMTP id y11mr27802170qvp.68.1582228431160; Thu, 20 Feb 2020 11:53:51 -0800 (PST) X-Received: by 2002:a0c:eacb:: with SMTP id y11mr27802131qvp.68.1582228430870; Thu, 20 Feb 2020 11:53:50 -0800 (PST) Received: from xz-x1.redhat.com ([104.156.64.75]) by smtp.gmail.com with ESMTPSA id r37sm293401qtj.44.2020.02.20.11.53.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Feb 2020 11:53:50 -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 12/16] mm: Introduce FAULT_FLAG_INTERRUPTIBLE Date: Thu, 20 Feb 2020 14:53:48 -0500 Message-Id: <20200220195348.16302-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 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 888272621f38..c076d3295958 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 08ca35d3c341..ff653f9136dd 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -378,22 +378,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" }, \ @@ -404,7 +420,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.24.1