From patchwork Tue Nov 6 07:49:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Souptick Joarder X-Patchwork-Id: 10669849 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4AC4614E2 for ; Tue, 6 Nov 2018 07:46:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B5B02A1C6 for ; Tue, 6 Nov 2018 07:46:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1C8E42A1CE; Tue, 6 Nov 2018 07:46:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6BF752A1C6 for ; Tue, 6 Nov 2018 07:46:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BC7126B02C3; Tue, 6 Nov 2018 02:46:06 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B75A76B02C4; Tue, 6 Nov 2018 02:46:06 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A8DFD6B02C5; Tue, 6 Nov 2018 02:46:06 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by kanga.kvack.org (Postfix) with ESMTP id 61E6D6B02C3 for ; Tue, 6 Nov 2018 02:46:06 -0500 (EST) Received: by mail-pl1-f198.google.com with SMTP id b8-v6so12567878pls.11 for ; Mon, 05 Nov 2018 23:46:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:date:from:to:cc:subject :message-id:mime-version:content-disposition:user-agent; bh=LoPekBv4ecKgNNEo5tW7CAeKBEcSexsyyurwBOBdMEw=; b=TX/D921+KD3J25EBuo2vcV+qk846qAQhMy/jqNPCc3WDHuLYrtLVDCwoVszLw8PJq1 P53uCnrpgsA0fpdB7s+mjDC6MgKqyTk/Ssj3o31fvYbP6KyGD0IER7I5SDsMBWiyA5N6 m88LvokImfZybkuz/gR8meB52a59x2XoKRcqUUIqH9OPxkqwDTqj05t6nDZgq37YpgXb 4Qoe9zAXY+LeEoxbcjm+8OwmAwaD0ZM83bdW/8a9M4schiIovzWUe1BUgl5V0icD1wii dtOO3lkHZgESfqhN11TD9rv3jqiYnutmxsaZLbs0WafFjCW4Fp30eDYjI2K48IoInP5I iuZg== X-Gm-Message-State: AGRZ1gITh3h92ogzw9Fkc/H/vJCXPoDAgX1VpNukCtBEOLWk6xL+Ic6Z QNMBt/wd6uAAx0NHF1WjfAc8ishUF6WSdEcBYxfpnqY0KS14HL+vFbmHHSuYE281qtRMqaWtG52 8BuFryZjSsutfTw6k1Nzvo4S4UrmSmUb4cSLCAkZaSUafi5vE6IMghsWjdF6edN9jbJu3xFWyWf +4WzjMr3ECKiTa3kT7eMQPKfksoxb7BbM+1UE1ZTtQ/td0I1UNz+csvkYaRQuplcwk2suV6Lny8 G3S5ADOk16fwzaM+B+0ca8HP2PCnu31NKJFRvprJwDSu0zO9TvW32ESAVn2uknbJrJQ0RVBAOdk Kh/7hFf2dpfsSPbu83rL5Lt52ZG2gycfyhzeME2jmEOvhzvmVMmzLMbRBrtrP2ZRsQSmnoSuQlA l X-Received: by 2002:aa7:8498:: with SMTP id u24-v6mr25153018pfn.220.1541490365990; Mon, 05 Nov 2018 23:46:05 -0800 (PST) X-Received: by 2002:aa7:8498:: with SMTP id u24-v6mr25152972pfn.220.1541490364732; Mon, 05 Nov 2018 23:46:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541490364; cv=none; d=google.com; s=arc-20160816; b=JfH7nrJp/yx1U3i3vUOPL5fiEF/5GhzYJxDw3ht3dPVbtiVxUo2ElXB4+L5p/Rrs4+ ijgmnAHkb/xA7NjfarMDRLFuf3VPLtwqzyZ61j+9tmIX7Ll8PA27Oe/OySfasQEiasEz JcO3JPYewj+bAZPvpULXmYvjgn5HrjF/tjNW4lOD0Xrn7nICXa1d1dN3xmpByrIyiuSd M+6/j3STpAAJN9qjp4bs1ObzWMo6/hklJeiH+SGTXeu2bWnOjvFnjpmRNi3zffpqjqTB iZHDE8HMiGtYbh2XcH1UJDn6PAcX6Aud6vF1CfhKBjwZSFbVKU5vk9/H9CWHNMt2UHMX TRSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:content-disposition:mime-version:message-id:subject:cc :to:from:date:dkim-signature; bh=LoPekBv4ecKgNNEo5tW7CAeKBEcSexsyyurwBOBdMEw=; b=r4mjKJ6N/y9+MOw1x/kmqJhpmiQoruw3t9PUpgUXo9go4aE3ZHVaxmWoTzqm655Mrk yWN+VPpCRnFg2xtWee05rFEUiS5Cwe9FX2r3wcPoRpl8QIoSjGySXPCBF0KgJ9HcOnTt ZdKl2bb4VJbOkVf9r21lCTCBsF183oRRaFeaOT+3xSqmw55vlHb5fPkCZXFdnFE/8FO1 fkjt//Px7mkpkQoJumG5WOMymgOeYsycSwQaEUllfj9UpOG/BPiCqnHYRFtpkKxGwLQ9 Ah6+JSYxsJPQ3HnP5CXn1NVRAdJfMEgER7RbRWPQVjXmK44A0fI28jt9cS05vPXNMzdF lJiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="VHrUCI/q"; spf=pass (google.com: domain of jrdr.linux@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jrdr.linux@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id bj10-v6sor9047193plb.25.2018.11.05.23.46.04 for (Google Transport Security); Mon, 05 Nov 2018 23:46:04 -0800 (PST) Received-SPF: pass (google.com: domain of jrdr.linux@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="VHrUCI/q"; spf=pass (google.com: domain of jrdr.linux@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=jrdr.linux@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=LoPekBv4ecKgNNEo5tW7CAeKBEcSexsyyurwBOBdMEw=; b=VHrUCI/qHIB6awukFBbx6Ej+M+JEpfrSip7vIcOekvVO9a5ITIV55GRLl8iR84CKhU wND1OKDQ4MIZythqmUOs6VTTN7ZQ93lQUGLfzvBfdgN9wAHGxgF6FIHfrlsJLlIke715 ayZOJrSJb/KGn/3JMrHXApnglwbqh+MeBfpVMlZO/KGPJEEtWFd5vpV69P0iWXGzOgnx cNs1vKE1nwGPiDyRoUWBM7FERjxn5DCmLyIfC8xfS5nnggRPIVWqvaYYtIrjeP+FqjK7 CfEg6mvwi9m1V1Jrq8eZcOPDOU77yxD4nSHTDErf/LBWBcTOGLpA6lHjitzFS3eEQrDP 0sMw== X-Google-Smtp-Source: AJdET5csnpgnlXTXojYEz93SOw5hPVclTJzYRyeUa8iMUmrKgQaNTbC9J1vznGAscOCt7WXSyMc9uQ== X-Received: by 2002:a17:902:8b8a:: with SMTP id ay10-v6mr25221832plb.130.1541490364194; Mon, 05 Nov 2018 23:46:04 -0800 (PST) Received: from jordon-HP-15-Notebook-PC ([103.227.97.85]) by smtp.gmail.com with ESMTPSA id z9-v6sm22039200pfg.174.2018.11.05.23.46.02 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 05 Nov 2018 23:46:02 -0800 (PST) Date: Tue, 6 Nov 2018 13:19:34 +0530 From: Souptick Joarder To: willy@infradead.org, akpm@linux-foundation.org, mhocko@suse.com, kirill.shutemov@linux.intel.com, dan.j.williams@intel.com, vbabka@suse.cz, riel@redhat.com, rppt@linux.ibm.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] mm: Create the new vm_fault_t type Message-ID: <20181106074934.GA27620@jordon-HP-15-Notebook-PC> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Page fault handlers are supposed to return VM_FAULT codes, but some drivers/file systems mistakenly return error numbers. Now that all drivers/file systems have been converted to use the vm_fault_t return type, change the type definition to no longer be compatible with 'int'. By making it an unsigned int, the function prototype becomes incompatible with a function which returns int. Sparse will detect any attempts to return a value which is not a VM_FAULT code. VM_FAULT_SET_HINDEX and VM_FAULT_GET_HINDEX values are changed to avoid conflict with other VM_FAULT codes. Signed-off-by: Souptick Joarder --- v2: Updated the change log and corrected the document part. name added to the enum that kernel-doc able to parse it. include/linux/mm.h | 46 ------------------------------ include/linux/mm_types.h | 73 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 72 insertions(+), 47 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index fcf9cc9..511a3ce 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1267,52 +1267,6 @@ static inline void clear_page_pfmemalloc(struct page *page) } /* - * Different kinds of faults, as returned by handle_mm_fault(). - * Used to decide whether a process gets delivered SIGBUS or - * just gets major/minor fault counters bumped up. - */ - -#define VM_FAULT_OOM 0x0001 -#define VM_FAULT_SIGBUS 0x0002 -#define VM_FAULT_MAJOR 0x0004 -#define VM_FAULT_WRITE 0x0008 /* Special case for get_user_pages */ -#define VM_FAULT_HWPOISON 0x0010 /* Hit poisoned small page */ -#define VM_FAULT_HWPOISON_LARGE 0x0020 /* Hit poisoned large page. Index encoded in upper bits */ -#define VM_FAULT_SIGSEGV 0x0040 - -#define VM_FAULT_NOPAGE 0x0100 /* ->fault installed the pte, not return page */ -#define VM_FAULT_LOCKED 0x0200 /* ->fault locked the returned page */ -#define VM_FAULT_RETRY 0x0400 /* ->fault blocked, must retry */ -#define VM_FAULT_FALLBACK 0x0800 /* huge page fault failed, fall back to small */ -#define VM_FAULT_DONE_COW 0x1000 /* ->fault has fully handled COW */ -#define VM_FAULT_NEEDDSYNC 0x2000 /* ->fault did not modify page tables - * and needs fsync() to complete (for - * synchronous page faults in DAX) */ - -#define VM_FAULT_ERROR (VM_FAULT_OOM | VM_FAULT_SIGBUS | VM_FAULT_SIGSEGV | \ - VM_FAULT_HWPOISON | VM_FAULT_HWPOISON_LARGE | \ - VM_FAULT_FALLBACK) - -#define VM_FAULT_RESULT_TRACE \ - { VM_FAULT_OOM, "OOM" }, \ - { VM_FAULT_SIGBUS, "SIGBUS" }, \ - { VM_FAULT_MAJOR, "MAJOR" }, \ - { VM_FAULT_WRITE, "WRITE" }, \ - { VM_FAULT_HWPOISON, "HWPOISON" }, \ - { VM_FAULT_HWPOISON_LARGE, "HWPOISON_LARGE" }, \ - { VM_FAULT_SIGSEGV, "SIGSEGV" }, \ - { VM_FAULT_NOPAGE, "NOPAGE" }, \ - { VM_FAULT_LOCKED, "LOCKED" }, \ - { VM_FAULT_RETRY, "RETRY" }, \ - { VM_FAULT_FALLBACK, "FALLBACK" }, \ - { VM_FAULT_DONE_COW, "DONE_COW" }, \ - { VM_FAULT_NEEDDSYNC, "NEEDDSYNC" } - -/* Encode hstate index for a hwpoisoned large page */ -#define VM_FAULT_SET_HINDEX(x) ((x) << 12) -#define VM_FAULT_GET_HINDEX(x) (((x) >> 12) & 0xf) - -/* * Can be called by the pagefault handler when it gets a VM_FAULT_OOM. */ extern void pagefault_out_of_memory(void); diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 5ed8f62..beee607 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -22,7 +22,6 @@ #endif #define AT_VECTOR_SIZE (2*(AT_VECTOR_SIZE_ARCH + AT_VECTOR_SIZE_BASE + 1)) -typedef int vm_fault_t; struct address_space; struct mem_cgroup; @@ -609,6 +608,78 @@ static inline bool mm_tlb_flush_nested(struct mm_struct *mm) struct vm_fault; +/** + * typedef vm_fault_t - Return type for page fault handlers. + * + * Page fault handlers return a bitmask of %VM_FAULT values. + */ +typedef __bitwise unsigned int vm_fault_t; + +/** + * enum - VM_FAULT code + * + * Page fault handlers return a bitmask of these values to tell + * the core VM what happened when handling the fault. Used to decide + * whether a process gets delivered SIGBUS or just gets major/minor + * fault counters bumped up. + * + * @VM_FAULT_OOM: Out Of Memory + * @VM_FAULT_SIGBUS: Bad access + * @VM_FAULT_MAJOR: Page read from storage + * @VM_FAULT_WRITE: Special case for get_user_pages + * @VM_FAULT_HWPOISON: Hit poisoned small page + * @VM_FAULT_HWPOISON_LARGE: Hit poisoned large page. Index encoded + * in upper bits + * @VM_FAULT_SIGSEGV: segmentation fault + * @VM_FAULT_NOPAGE: ->fault installed the pte, not return page + * @VM_FAULT_LOCKED: ->fault locked the returned page + * @VM_FAULT_RETRY: ->fault blocked, must retry + * @VM_FAULT_FALLBACK: huge page fault failed, fall back to small + * @VM_FAULT_DONE_COW: ->fault has fully handled COW + * @VM_FAULT_NEEDDSYNC: ->fault did not modify page tables and needs + * fsync() to complete (for synchronous page faults + * in DAX) + */ +enum vm_fault_reason { + VM_FAULT_OOM = (__force vm_fault_t)0x000001, + VM_FAULT_SIGBUS = (__force vm_fault_t)0x000002, + VM_FAULT_MAJOR = (__force vm_fault_t)0x000004, + VM_FAULT_WRITE = (__force vm_fault_t)0x000008, + VM_FAULT_HWPOISON = (__force vm_fault_t)0x000010, + VM_FAULT_HWPOISON_LARGE = (__force vm_fault_t)0x000020, + VM_FAULT_SIGSEGV = (__force vm_fault_t)0x000040, + VM_FAULT_NOPAGE = (__force vm_fault_t)0x000100, + VM_FAULT_LOCKED = (__force vm_fault_t)0x000200, + VM_FAULT_RETRY = (__force vm_fault_t)0x000400, + VM_FAULT_FALLBACK = (__force vm_fault_t)0x000800, + VM_FAULT_DONE_COW = (__force vm_fault_t)0x001000, + VM_FAULT_NEEDDSYNC = (__force vm_fault_t)0x002000, + VM_FAULT_HINDEX_MASK = (__force vm_fault_t)0x0f0000, +}; + +/* Encode hstate index for a hwpoisoned large page */ +#define VM_FAULT_SET_HINDEX(x) ((__force vm_fault_t)((x) << 16)) +#define VM_FAULT_GET_HINDEX(x) (((x) >> 16) & 0xf) + +#define VM_FAULT_ERROR (VM_FAULT_OOM | VM_FAULT_SIGBUS | \ + VM_FAULT_SIGSEGV | VM_FAULT_HWPOISON | \ + VM_FAULT_HWPOISON_LARGE | VM_FAULT_FALLBACK) + +#define VM_FAULT_RESULT_TRACE \ + { VM_FAULT_OOM, "OOM" }, \ + { VM_FAULT_SIGBUS, "SIGBUS" }, \ + { VM_FAULT_MAJOR, "MAJOR" }, \ + { VM_FAULT_WRITE, "WRITE" }, \ + { VM_FAULT_HWPOISON, "HWPOISON" }, \ + { VM_FAULT_HWPOISON_LARGE, "HWPOISON_LARGE" }, \ + { VM_FAULT_SIGSEGV, "SIGSEGV" }, \ + { VM_FAULT_NOPAGE, "NOPAGE" }, \ + { VM_FAULT_LOCKED, "LOCKED" }, \ + { VM_FAULT_RETRY, "RETRY" }, \ + { VM_FAULT_FALLBACK, "FALLBACK" }, \ + { VM_FAULT_DONE_COW, "DONE_COW" }, \ + { VM_FAULT_NEEDDSYNC, "NEEDDSYNC" } + struct vm_special_mapping { const char *name; /* The name, e.g. "[vdso]". */