From patchwork Thu May 10 17:48:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Souptick Joarder X-Patchwork-Id: 10392115 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 63E7160353 for ; Thu, 10 May 2018 17:46:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5289928BAB for ; Thu, 10 May 2018 17:46:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 472C128C86; Thu, 10 May 2018 17:46:26 +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 D2E1228BAB for ; Thu, 10 May 2018 17:46:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 629C46B0631; Thu, 10 May 2018 13:46:24 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5D8DD6B0632; Thu, 10 May 2018 13:46:24 -0400 (EDT) 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 47ACA6B0633; Thu, 10 May 2018 13:46:24 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f70.google.com (mail-pl0-f70.google.com [209.85.160.70]) by kanga.kvack.org (Postfix) with ESMTP id 001896B0631 for ; Thu, 10 May 2018 13:46:23 -0400 (EDT) Received: by mail-pl0-f70.google.com with SMTP id o23-v6so1572154pll.12 for ; Thu, 10 May 2018 10:46:23 -0700 (PDT) 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=ISflgWEn+/+HbZXz14bH/IxQxAgat7Yk3LJhNOhbtbg=; b=SfENHBzunZw88pcmAWCYBiQMaPd+1PQrBTYzUxsujCDzK4sywAcIQ4rIJLzpSVE21n HluHVTlWn65hIFEOEmQqJQ8+mU+8YDcYb9J1orAo3a6+CGPzqW5HJq1tJMsth/2zXYJY FC415GhqUWCDAxOgLA02EubygiB0duiokrnUfSKdPlfEMFdXjElLVbHPwBsB9fjhD3vZ HVK7Yp4vvdorGKoWdXpCN+62wfM3p2Y1UXzaacV8os+EBxuoK0RKlHIhgljbacZFr47+ LfHUJf9pkEEqceA2hMVLRDSJgmHcozKy4UIuV0ZpSZ4k/7DmsKJdNVLevmFKiVdeVNvE B97g== X-Gm-Message-State: ALKqPwefGoHQwcZ1bdcItwkrYF21X8aBl8U1HezAipN3kGGqwcrHAAQd xwqCEl1/JuzsPfozJ2NWArc7S/d5Vs1oYZ/aZ1iRim5joO4gzyFsXfKPmVPfiPnIhIVkd4+vkJ7 5WXQweEcRgw87c836Vhhp5Uy/uBG4cobqAROhyGmNfu7yqkG5bIElavf9sYLHqkYn5cA8rQYGBt Qqa8aATfOuyUBUex044ewbOTqwtSSGph1POuwl+9XMYZ7AcDU8x59HmSo7jjbOYxJJSZHSZ0HbL 1Huj/Y9AwmlM02x/LK6R+1eLl8OnNyW2VxFqiAIae2/a4EjKMExCZc4aeCgdx5ZT6dS3zDuhLlc 2HldIBeBywUVSz1ylTng9XRxw/WTgrZ8ZMmU6AMWHSDTtOszwc6cR8L67UDbxAO+KeKj3VcUaxH 3 X-Received: by 2002:a17:902:264:: with SMTP id 91-v6mr2199551plc.341.1525974383501; Thu, 10 May 2018 10:46:23 -0700 (PDT) X-Received: by 2002:a17:902:264:: with SMTP id 91-v6mr2199505plc.341.1525974382485; Thu, 10 May 2018 10:46:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525974382; cv=none; d=google.com; s=arc-20160816; b=dHwM9YD3cQslTsg/IUssheG39mtlwXKw4mSUCWdroQ6tgSiB4iPT9mlnbXc04HVkZE 4ua0kCvpm2GNsU3OEXKaBhl5XKJMikCwG8xCJNmxqVzWI6b1eFvsmqo9zqhN0AW5AbbO 2XGupc+IbESSEKoF678b69lFGnp1WmwWyos14FdeJKVO5W35HAruBVmla71/6UzWCZKc HNaivuqo6Wz0YzFEEuDg8/tYAydY+ZyVcJQp42zp9H5FJEHetIelQZA3D7fhhvbj6aVE 1i1mfPlJWwnzvuiN/b5K3MZpExwnCkr8/NGSWJD4k4yjbHkPA50+J48inxV6r9q3sJJ/ Y+dg== 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:arc-authentication-results; bh=ISflgWEn+/+HbZXz14bH/IxQxAgat7Yk3LJhNOhbtbg=; b=uKwn+t42lDUNWYlmeKCss0kVW2FVd2ZNqG8TNtthRJnzgzwPE4e+6ubmxoI5XpfhsE UsT9xO8/cPDZFkVyG4GELHCkZhSB8enLcUhfNGEfvYxsYPQWSFVC3mfgkSYamHj0APSz HvMWoYl2uyDce5JjUUH6G4dIIWgw0PXyS8QBDZ9fg5buvArWa/L0Wi3tkCprO/JZIk5e 2oiy2Kd8HO5AZfoVNzNO1HcyO8q6yl46D/na7E0ZZLZlMMio8ce2ZvCc0oDbodcab9jF vANTcHLLTL3qMURAvfGeE+t6sOdtEmC0LmmqQfRDHMvp5SsbVLumGjvKNdTajzMi9jsK SzlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=AMofyDqN; 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 k3-v6sor334388pgq.418.2018.05.10.10.46.22 for (Google Transport Security); Thu, 10 May 2018 10:46:22 -0700 (PDT) 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=AMofyDqN; 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=ISflgWEn+/+HbZXz14bH/IxQxAgat7Yk3LJhNOhbtbg=; b=AMofyDqNG+YNtgdKw4FIj7y01N/xFJX6rgeq4Dc121OPLBeNWmI++auDbyq5ubIHTs D/F/eDc9CqYgF3nKK0IHpIET6ykZUTlJKyiKH1rcBjFGu6PUSUbnJvHvWdMo7brp+ca8 QSJE5ZZDrav2gAx+gPQbguyUANP440WqDzZGC7LHn4n3+DIR/f890YG1+IgmkYrdl5cu uz/yH1Nn8dDPcZVsi6TZBPe678yTQbfGZJiv9ZujSw3VOZIc71Z+ukuLtzZYgMaiJ1o1 11m9F3iFnFjPOl+gszROqv3B1LNyhMVM+n8VOTYoXEYm2DYwdEoanegSkgEujsdsXTDo Tupw== X-Google-Smtp-Source: AB8JxZqhj8JJmCSpElLlaa7FKVjxS4uM5UKtQ6TowdbPvYC8jKeYaGB9duHpY2q5bLADzjfigkDVXQ== X-Received: by 2002:a63:7351:: with SMTP id d17-v6mr1776139pgn.297.1525974381367; Thu, 10 May 2018 10:46:21 -0700 (PDT) Received: from jordon-HP-15-Notebook-PC ([49.205.218.138]) by smtp.gmail.com with ESMTPSA id u86-v6sm4535648pfg.71.2018.05.10.10.46.18 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 10 May 2018 10:46:19 -0700 (PDT) Date: Thu, 10 May 2018 23:18:27 +0530 From: Souptick Joarder To: akpm@linux-foundation.org, willy@infradead.org Cc: linux-mm@kvack.org Subject: [PATCH v2] include: mm: Adding new inline function vmf_error Message-ID: <20180510174826.GA14268@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 Many places in drivers/ file systems, error was handled in a common way like below - ret = (ret == -ENOMEM) ? VM_FAULT_OOM : VM_FAULT_SIGBUS; This new inline function vmf_error() will replace this and return vm_fault_t type err. A lot of drivers and filesystems currently have a rather complex mapping of errno-to-VM_FAULT code. We have been able to eliminate a lot of it by just returning VM_FAULT codes directly from functions which are called exclusively from the fault handling path. Some functions can be called both from the fault handler and other context which are expecting an errno, so they have to continue to return an errno. Some users still need to choose different behaviour for different errnos, but vmf_error() captures the essential error translation that's common to all users, and those that need to handle additional errors can handle them first. Signed-off-by: Souptick Joarder Reviewed-by: Matthew Wilcox --- v2: Addressed Andrew's comment. Updated the change log. Modified vmf_error() to less verbose include/linux/mm.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index a4d8853..6ef5d94 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2453,6 +2453,13 @@ static inline vm_fault_t vmf_insert_pfn(struct vm_area_struct *vma, return VM_FAULT_NOPAGE; } +static inline vm_fault_t vmf_error(int err) +{ + if (err == -ENOMEM) + return VM_FAULT_OOM; + return VM_FAULT_SIGBUS; +} + struct page *follow_page_mask(struct vm_area_struct *vma, unsigned long address, unsigned int foll_flags, unsigned int *page_mask);