From patchwork Fri Feb 28 05:47:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arjun Roy X-Patchwork-Id: 11411561 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E625792A for ; Fri, 28 Feb 2020 05:47:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A4F0E246A1 for ; Fri, 28 Feb 2020 05:47:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dZoV5G0W" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A4F0E246A1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 88AD16B0006; Fri, 28 Feb 2020 00:47:26 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 83B4E6B0007; Fri, 28 Feb 2020 00:47:26 -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 7290D6B0008; Fri, 28 Feb 2020 00:47:26 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0146.hostedemail.com [216.40.44.146]) by kanga.kvack.org (Postfix) with ESMTP id 5AAFE6B0006 for ; Fri, 28 Feb 2020 00:47:26 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 272B08245571 for ; Fri, 28 Feb 2020 05:47:26 +0000 (UTC) X-FDA: 76538453292.07.egg44_7b12c180c1f52 X-Spam-Summary: 2,0,0,4c3721d09b2918eb,d41d8cd98f00b204,arjunroy.kdev@gmail.com,,RULES_HIT:41:69:355:379:541:800:960:973:988:989:1260:1311:1314:1345:1359:1431:1437:1515:1535:1543:1605:1711:1730:1747:1777:1792:2393:2559:2562:2740:3138:3139:3140:3141:3142:3865:3866:3867:3868:3870:3871:3872:3874:4117:4321:5007:6119:6261:6653:7576:7875:7901:7903:9413:9592:10004:11026:11658:11914:12043:12291:12296:12297:12438:12517:12519:12555:12679:12683:12895:13053:13894:14181:14394:14687:14721:21080:21444:21451:21627:21666:21795:21990:30025:30051:30054:30070,0,RBL:209.85.216.68:@gmail.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: egg44_7b12c180c1f52 X-Filterd-Recvd-Size: 6887 Received: from mail-pj1-f68.google.com (mail-pj1-f68.google.com [209.85.216.68]) by imf45.hostedemail.com (Postfix) with ESMTP for ; Fri, 28 Feb 2020 05:47:25 +0000 (UTC) Received: by mail-pj1-f68.google.com with SMTP id f2so4005625pjq.1 for ; Thu, 27 Feb 2020 21:47:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6If4TKyrcsv+UCNQk5iXzV2KO/tmAaLmjWZ2SW5AUi4=; b=dZoV5G0WuZuKh/DLYTEssNrdug1TY7xeF/c6JlPx2z3rWi4L3YxoKBmQi6s5ZCdT8x ph3BJffdg1JtMTYQOXgaCTiGeYka4WiR3xTjIJ+Yii5yQvJ17hvvoxlL/lAOXvsETufD h6V8LP1/Ktk4UMjRvu5KTYKLm3Rqvt/pBD25yV1zi2/4RiffPuNhcfsS02sGhgRV36Mv 8YCqF0yDXKENRy+vj70jh/5gTDbOnB6/hYHHUgZsGJrsklh2eJ4r53bJCFAQ77ovla6k dQcLrwmz3VvdNl2Xu4bFaPNObXsl5hKh+KJSSc8doODgxscJdP0uUDjsOSCg/fCpuh+N oLcQ== 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=6If4TKyrcsv+UCNQk5iXzV2KO/tmAaLmjWZ2SW5AUi4=; b=ZjLp8S37q7oCVdINkGiC19zfnBJtGkHdx14sZ/FThlk4uHmg8P9GywVQ2qmONEc1i0 HxYuMf8DkBCcpbHG+jfTNcT5ShULO/aDHTwdR1WCBGXCrVqGGMe+ydMtP510fdyHZGEF LPmEd2BYFOalz69ffQ0I+xrJSbj/qRnI7NDcnhRWEjcr2WAjbTxpEaECQ+hNmQBNaV3Z 0/dvQf4L3zdRPj+HdVxOh93uCnE7ZHQdpKGNAZ8UOyGvIKzO5DclAzmX0zukXo3eWUrY ZGDbHqK4N0qcqjbWJg33CZugXLHB5m6t6MpgX1pwXnW0dE05pB+JI+OzoGG1F5+p7R6Q YQgA== X-Gm-Message-State: APjAAAWtvBAC318n2qWmAVvzb1/kdYpYBHrKY2kLKxT2649lW4I3UMfE 5ZpM+qXAuM61I+gvLtCxFCA= X-Google-Smtp-Source: APXvYqxnQrxdzTi2VwENaBr6EHh6L0pqvtbAXg8F85J23dotFm/3h2IA9083NbvmM5P8aerc1UQnog== X-Received: by 2002:a17:902:6907:: with SMTP id j7mr2592291plk.88.1582868844719; Thu, 27 Feb 2020 21:47:24 -0800 (PST) Received: from phantasmagoria.svl.corp.google.com ([2620:15c:2c4:201:2b0a:8c1:6a84:1aa0]) by smtp.gmail.com with ESMTPSA id d3sm9027253pfn.113.2020.02.27.21.47.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2020 21:47:24 -0800 (PST) From: Arjun Roy To: davem@davemloft.net, akpm@linux-foundation.org, linux-mm@kvack.org Cc: arjunroy@google.com, soheil@google.com, edumazet@google.com, sfr@canb.auug.org.au, geert@linux-m68k.org Subject: [PATCH v3 mm 2/2] mm: vm_insert_pages() checks if pte_index defined. Date: Thu, 27 Feb 2020 21:47:14 -0800 Message-Id: <20200228054714.204424-2-arjunroy.kdev@gmail.com> X-Mailer: git-send-email 2.25.1.481.gfbce0eb801-goog In-Reply-To: <20200228054714.204424-1-arjunroy.kdev@gmail.com> References: <20200228054714.204424-1-arjunroy.kdev@gmail.com> MIME-Version: 1.0 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: From: Arjun Roy pte_index() is either defined as a macro (e.g. sparc64) or as an inlined function (e.g. x86). vm_insert_pages() depends on pte_index but it is not defined on all platforms (e.g. m68k). To fix compilation of vm_insert_pages() on architectures not providing pte_index(), we perform the following fix: 0. For platforms where it is meaningful, and defined as a macro, no change is needed. 1. For platforms where it is meaningful and defined as an inlined function, and we want to use it with vm_insert_pages(), we define a degenerate macro of the form: #define pte_index pte_index 2. vm_insert_pages() checks for the existence of a pte_index macro definition. If found, it implements a batched insert. If not found, it devolves to calling vm_insert_page() in a loop. This patch implements step 2. v3 of this patch fixes a compilation warning for an unused method. v2 of this patch moved a macro definition to a more readable location. Signed-off-by: Arjun Roy --- mm/memory.c | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index d6f834f7d145..47b28fcc73c2 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1460,18 +1460,6 @@ static int insert_page_into_pte_locked(struct mm_struct *mm, pte_t *pte, return 0; } -static int insert_page_in_batch_locked(struct mm_struct *mm, pmd_t *pmd, - unsigned long addr, struct page *page, pgprot_t prot) -{ - int err; - - if (!page_count(page)) - return -EINVAL; - err = validate_page_before_insert(page); - return err ? err : insert_page_into_pte_locked( - mm, pte_offset_map(pmd, addr), addr, page, prot); -} - /* * This is the old fallback for page remapping. * @@ -1500,8 +1488,21 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr, return retval; } +#ifdef pte_index +static int insert_page_in_batch_locked(struct mm_struct *mm, pmd_t *pmd, + unsigned long addr, struct page *page, pgprot_t prot) +{ + int err; + + if (!page_count(page)) + return -EINVAL; + err = validate_page_before_insert(page); + return err ? err : insert_page_into_pte_locked( + mm, pte_offset_map(pmd, addr), addr, page, prot); +} + /* insert_pages() amortizes the cost of spinlock operations - * when inserting pages in a loop. + * when inserting pages in a loop. Arch *must* define pte_index. */ static int insert_pages(struct vm_area_struct *vma, unsigned long addr, struct page **pages, unsigned long *num, pgprot_t prot) @@ -1556,6 +1557,7 @@ static int insert_pages(struct vm_area_struct *vma, unsigned long addr, *num = remaining_pages_total; return ret; } +#endif /* ifdef pte_index */ /** * vm_insert_pages - insert multiple pages into user vma, batching the pmd lock. @@ -1575,6 +1577,7 @@ static int insert_pages(struct vm_area_struct *vma, unsigned long addr, int vm_insert_pages(struct vm_area_struct *vma, unsigned long addr, struct page **pages, unsigned long *num) { +#ifdef pte_index const unsigned long end_addr = addr + (*num * PAGE_SIZE) - 1; if (addr < vma->vm_start || end_addr >= vma->vm_end) @@ -1586,6 +1589,18 @@ int vm_insert_pages(struct vm_area_struct *vma, unsigned long addr, } /* Defer page refcount checking till we're about to map that page. */ return insert_pages(vma, addr, pages, num, vma->vm_page_prot); +#else + unsigned long idx = 0, pgcount = *num; + int err; + + for (; idx < pgcount; ++idx) { + err = vm_insert_page(vma, addr + (PAGE_SIZE * idx), pages[idx]); + if (err) + break; + } + *num = pgcount - idx; + return err; +#endif /* ifdef pte_index */ } EXPORT_SYMBOL(vm_insert_pages);