Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp7198980imm; Tue, 28 Aug 2018 07:59:26 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYErMIxCipYu7eQ9C9vv8ROMkNu4ZblPFCqCfHWtJagcG/IlfgswImOyVZBA5N/Vgxg9AdP X-Received: by 2002:a63:fe4d:: with SMTP id x13-v6mr1951822pgj.152.1535468366441; Tue, 28 Aug 2018 07:59:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535468366; cv=none; d=google.com; s=arc-20160816; b=IU93FU+rS/ePT4Cc61zsT6+FCG5JcLDylyM/eJBRDV6/dMbNu7AFGMirQON6fH+i2e 1oE+bXcGTid954wsae1wJBSouck6HWOppVWM2gONIrC+wzSpHgybTfTSKsiy13uvLneB oY1pU967oV7Nu8WbXOONOAs3OHXnG5vyculV+IkVErPpz2fqB4klBKHzvwiZQFCc+QYi XGgTNz8AG5xoikN6FRArZSGPAduuwfvhyfws95O2mO8bMgjWLQa3Fy8hR8JC/k861HQq 3vZENZI8laBzJcdgfIzhSf0THHgQi1pUI8vStXVwbe7USaxo5Eqy9OQegYu3aWLNhTQp o7nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=zU0QkCVvQYJGUULQkXZrz90Twq+68Z+fITs7I2vkboA=; b=uvDRrEMFW5nApkIfUWp0wuoqT463L3bDqPIl9NxHrKNF576BAUUx8nfabSj2MaqJiU 7CoETN9wZnU7QESOd+JVOjXgNY7oBG+CGFDRYOV8jVZLnq5RvIAFfCX1zEMg/UeDOaJS 69eJjNR8s2DlIbG6QQNCgkRiAzCjke92lQI6PypwvNmDwnMcPI+SvKSEOjkziaHzDr5w wfR7YBmfuxKaKQB/GRX6xVHGFFuSHWxq2FwjMLBrozoNeLxYYshPicFyUTQdHQ31b8gG OjYITsm38cbQTIS1KFsl4uz1BQftKUsTyUeCYrmD5RuJMB4PXtJCD4JeY/1pVIktIiyY epTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b="rl9IcXn/"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n11-v6si1322279pgl.133.2018.08.28.07.59.11; Tue, 28 Aug 2018 07:59:26 -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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b="rl9IcXn/"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728531AbeH1Str (ORCPT + 99 others); Tue, 28 Aug 2018 14:49:47 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:57732 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728506AbeH1Stq (ORCPT ); Tue, 28 Aug 2018 14:49:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=zU0QkCVvQYJGUULQkXZrz90Twq+68Z+fITs7I2vkboA=; b=rl9IcXn/KXyLGct7CVIKh2iPr gqmioch5zYkp7rkujjTNwIXLFSBWZ4S6GmT/HwAkGeOSh1fQCMtzfFUXAvVRbGP9xZutrxNonipiq acYSRD5CEblGbux3PZjVtzj8k+PlL/MHqbnk6PJvlOqyjsaa3w3WzkFlpdh50NuC5cGC6bh8fK4PN +w/8qKmAG3VocQ/T7ZEbd22JMjwZj0xpGIiMJ0Pf3m8UkfOpozxBr0hH6ASp3IEl8e/9RkMpu3kjb HS1K3fxHQngkkBmgFz8YWa9RokyXB12l6lsiP3gqA/8mVP2QCu0ZeCZK7SKYT6P4D2T2dOzE3IS6S B3OhRaMNA==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fufR7-0003Cu-Ie; Tue, 28 Aug 2018 14:57:41 +0000 From: Matthew Wilcox To: Andrew Morton Cc: Matthew Wilcox , Nicolas Pitre , Souptick Joarder , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 08/10] mm: Inline vm_insert_pfn_prot into caller Date: Tue, 28 Aug 2018 07:57:26 -0700 Message-Id: <20180828145728.11873-9-willy@infradead.org> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180828145728.11873-1-willy@infradead.org> References: <20180828145728.11873-1-willy@infradead.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org vm_insert_pfn_prot() is only called from vmf_insert_pfn_prot(), so inline it and convert some of the errnos into vm_fault codes earlier. Signed-off-by: Matthew Wilcox --- mm/memory.c | 55 +++++++++++++++++++++++------------------------------ 1 file changed, 24 insertions(+), 31 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index d5ccbadd81c1..9e97926fee19 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1819,36 +1819,6 @@ static int insert_pfn(struct vm_area_struct *vma, unsigned long addr, return retval; } -static int vm_insert_pfn_prot(struct vm_area_struct *vma, unsigned long addr, - unsigned long pfn, pgprot_t pgprot) -{ - int ret; - /* - * Technically, architectures with pte_special can avoid all these - * restrictions (same for remap_pfn_range). However we would like - * consistency in testing and feature parity among all, so we should - * try to keep these invariants in place for everybody. - */ - BUG_ON(!(vma->vm_flags & (VM_PFNMAP|VM_MIXEDMAP))); - BUG_ON((vma->vm_flags & (VM_PFNMAP|VM_MIXEDMAP)) == - (VM_PFNMAP|VM_MIXEDMAP)); - BUG_ON((vma->vm_flags & VM_PFNMAP) && is_cow_mapping(vma->vm_flags)); - BUG_ON((vma->vm_flags & VM_MIXEDMAP) && pfn_valid(pfn)); - - if (addr < vma->vm_start || addr >= vma->vm_end) - return -EFAULT; - - if (!pfn_modify_allowed(pfn, pgprot)) - return -EACCES; - - track_pfn_insert(vma, &pgprot, __pfn_to_pfn_t(pfn, PFN_DEV)); - - ret = insert_pfn(vma, addr, __pfn_to_pfn_t(pfn, PFN_DEV), pgprot, - false); - - return ret; -} - /** * vmf_insert_pfn_prot - insert single pfn into user vma with specified pgprot * @vma: user vma to map to @@ -1870,7 +1840,30 @@ static int vm_insert_pfn_prot(struct vm_area_struct *vma, unsigned long addr, vm_fault_t vmf_insert_pfn_prot(struct vm_area_struct *vma, unsigned long addr, unsigned long pfn, pgprot_t pgprot) { - int err = vm_insert_pfn_prot(vma, addr, pfn, pgprot); + int err; + + /* + * Technically, architectures with pte_special can avoid all these + * restrictions (same for remap_pfn_range). However we would like + * consistency in testing and feature parity among all, so we should + * try to keep these invariants in place for everybody. + */ + BUG_ON(!(vma->vm_flags & (VM_PFNMAP|VM_MIXEDMAP))); + BUG_ON((vma->vm_flags & (VM_PFNMAP|VM_MIXEDMAP)) == + (VM_PFNMAP|VM_MIXEDMAP)); + BUG_ON((vma->vm_flags & VM_PFNMAP) && is_cow_mapping(vma->vm_flags)); + BUG_ON((vma->vm_flags & VM_MIXEDMAP) && pfn_valid(pfn)); + + if (addr < vma->vm_start || addr >= vma->vm_end) + return VM_FAULT_SIGBUS; + + if (!pfn_modify_allowed(pfn, pgprot)) + return VM_FAULT_SIGBUS; + + track_pfn_insert(vma, &pgprot, __pfn_to_pfn_t(pfn, PFN_DEV)); + + err = insert_pfn(vma, addr, __pfn_to_pfn_t(pfn, PFN_DEV), pgprot, + false); if (err == -ENOMEM) return VM_FAULT_OOM; -- 2.18.0