Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1765282imu; Tue, 6 Nov 2018 04:06:09 -0800 (PST) X-Google-Smtp-Source: AJdET5cosimKkKpWdyjcy8svBeblYAekIE2rv8YiAZ1UNrY96AzsDjIaV6mSto2UZrtcQpK298oj X-Received: by 2002:a63:41c2:: with SMTP id o185-v6mr23233151pga.11.1541505969678; Tue, 06 Nov 2018 04:06:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541505969; cv=none; d=google.com; s=arc-20160816; b=rv6w8ZISHQlgBcEsJMTUZKxuuOJXQhBwrokH29wUlaOJ350H5jJuQX0xsYqqmJVWS/ MxdvAqRIMHnwup01g9xMggkyLPh2G+mSIubssBUpwd2IlYIJ1DhyEM/XpQjmQNyDLYie cY/5N+alm5tE1m82IEDujSPmO6TDxcFXISHls6YBSTUNBop60t5OVq7RXnKAkRVFQ41w fEmL1HnDe+jCXd1ITwEcGkzijouUxSBV1ZcSG+pXSYBfkBL3WErKXPpYaUSb4IDqwIKQ rMxNJOrfkW0tUAhk6bdL29LhuOTbf6+vXClanUR2z0+rDzyoxJ0kzRBK3HsZDRFXlo5o c7FA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=RiHdbdvqYpYTFAYcZLs7KWL1xgogOKzdaojbQFdACIM=; b=dNAWJymyUiyp102CArr5Vy/oiIrC/iWwzU0Ia4E1PySI1LJD9md1u29wRy/9+QuZeL zRzv+JW7QO4E8KfHrGeL2QWHPtcIlr+vUNQZBQUNrly9CzLIKmRny8p8WncZvUxayv1t BuTliWMJnYIACUWUJTeB93MMzI9n7FZoqtIbh02/OFV7WO0Au0o6Kx8+hPrkyLiIg+uw SXfudJCxTgwNE867C4ZUy6JDG2YDdlFbZiLsNlTxnBctxkPJSL4YS4CwWI6wdjEsrouQ YZXggq8uEkJu2H/hsB3S47gLs4cIPxnPPz0KIOL/H1rtIFWIFHe3HJJ5TVLaFXy7QEzc 7oJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=EDOikO6A; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r3-v6si14307474plo.97.2018.11.06.04.05.48; Tue, 06 Nov 2018 04:06:09 -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=@gmail.com header.s=20161025 header.b=EDOikO6A; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730698AbeKFV2G (ORCPT + 99 others); Tue, 6 Nov 2018 16:28:06 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:36268 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726976AbeKFV2F (ORCPT ); Tue, 6 Nov 2018 16:28:05 -0500 Received: by mail-pf1-f195.google.com with SMTP id j22-v6so6034057pfh.3 for ; Tue, 06 Nov 2018 04:03:12 -0800 (PST) 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=RiHdbdvqYpYTFAYcZLs7KWL1xgogOKzdaojbQFdACIM=; b=EDOikO6AVzvimyPTNvfFb5UQuBcVJLYRC9L14XuTNNVWclyf/qegleCt9wHiRxeIyU cs5uOmJ8FpSQCEphkY+ApQffUoE9efK0fOnIv3+2nmDQn0tRNhSf7bZTv5lNGiGjE+J1 ZBlMPGglgJlYez610J6cVh3z2lbff7aEPU6ExGJSFaRMAEAx5NKaoLYt7J0mwQfncf8a 3jR/gwnuzfPc0GBrlEzQRCLPqzxCxuT6Q+uf2JjmZXnMhqi+KbVD23ahlrvQlxyNqyKF fj+/AvFiMMyp/wt4K4rqmucDjHX8+CvTj25Pk3MP6i3ZuC8OKPduUHewh4o3GA7O5Wz3 Hr0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=RiHdbdvqYpYTFAYcZLs7KWL1xgogOKzdaojbQFdACIM=; b=AGBpYVW2m5poBCr71rOtYMKAlMfK06d94Q2BrMiNTNHIkEv04tNGh5GouRspZhSeD4 Q9tf/DkIgGD7LTD9TjQv4oXyWeqNsdtdT72jMN1EwBW8EoaeIVJoE6dTjmC5/HB5ys0I yiiLr5QiIqsDmKIAJFozFMiGPpEs+ya0QPESo5HosAFwpALtxYkFUFJyorL9LmgxSJXH olIKT6lcmLjLlPRfx+GEABnp4JXs/WuX7LrDutIGAHlGx0le/SVplOFYBt7Yy1kggdW7 D2PY+lh3kvYsDH7YwCGUhFEpVRlKJU0Zdv2DCcREzbI2MC1sayJlxQdn0zPt2WvC8Xv8 XVUg== X-Gm-Message-State: AGRZ1gK94NYkuPu18rec1VzC3eEAdY/xJlTH0RVgjYgL920HkNcBrJ0i zuJi3pxAXQ4jHnrWkl58IQMIoOcT X-Received: by 2002:a63:2e02:: with SMTP id u2mr3622802pgu.9.1541505791918; Tue, 06 Nov 2018 04:03:11 -0800 (PST) Received: from jordon-HP-15-Notebook-PC ([103.227.97.195]) by smtp.gmail.com with ESMTPSA id y144-v6sm66553044pfb.81.2018.11.06.04.03.10 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 06 Nov 2018 04:03:10 -0800 (PST) Date: Tue, 6 Nov 2018 17:36:42 +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 v3] mm: Create the new vm_fault_t type Message-ID: <20181106120544.GA3783@jordon-HP-15-Notebook-PC> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. v3: Corrected the documentation. 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..cb25016 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_reason - 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) + * @VM_FAULT_HINDEX_MASK: mask HINDEX value + * + */ +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]". */ -- 1.9.1