From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.5 required=3.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7B574C3F2CD for ; Fri, 28 Feb 2020 00:47:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3B4BC2064A for ; Fri, 28 Feb 2020 00:47:24 +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="b1APUtjK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3B4BC2064A 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 DAFE46B0006; Thu, 27 Feb 2020 19:47:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D877F6B0007; Thu, 27 Feb 2020 19:47:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C50696B0008; Thu, 27 Feb 2020 19:47:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0143.hostedemail.com [216.40.44.143]) by kanga.kvack.org (Postfix) with ESMTP id AC7D16B0006 for ; Thu, 27 Feb 2020 19:47:23 -0500 (EST) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id A4F1F8245571 for ; Fri, 28 Feb 2020 00:47:23 +0000 (UTC) X-FDA: 76537697166.02.story44_7abb0d6f4f934 X-HE-Tag: story44_7abb0d6f4f934 X-Filterd-Recvd-Size: 5826 Received: from mail-pj1-f66.google.com (mail-pj1-f66.google.com [209.85.216.66]) by imf33.hostedemail.com (Postfix) with ESMTP for ; Fri, 28 Feb 2020 00:47:23 +0000 (UTC) Received: by mail-pj1-f66.google.com with SMTP id m13so527321pjb.2 for ; Thu, 27 Feb 2020 16:47:22 -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=3RhHwg8Qv8DiMew65bSH/cdRUQhhn0ZVX5Ye2kBGwW0=; b=b1APUtjKbqQ9Zr6IdZuh+Y8oU1rC+BiyPzz5Wejnr3AeNiuDNnToy43yBBBn8ck5zM I+IQrJ7q6yYNitxJp4AlxBlPDPYf7Bw88seBbxvQVre82AikX4j++8MqCB1ZeCyh2hxM zeeapL/+PL9hZzfnqeY1zS/vKrcBlH88hpEceh6xnUyh8H+GskCn5YP0sdMiJE5tJJT7 L9SOcCt0MXHfXTZGkK9Jt6RvOh6mosFDVG8RXkI/q7xd9lg3xMzi20o4RX7h5u8FZ57U 35OyAUQMTPWfn0X/p9SPRqB7QMVA1GZpC5f46kYY0g861F9/mGXEy6C7Yhv6amruYeVj pB0g== 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=3RhHwg8Qv8DiMew65bSH/cdRUQhhn0ZVX5Ye2kBGwW0=; b=fX8e+bF90XleCFSOUkosAfELxSg+jfE9ouHqvULs8I6OWBKxNyEWf1mOdQL3lgWsqL xQD6Cr7e3iBUfz8pH6CJeUI9HXCHJu5oLx/kNdjm5E6nW7tgUKzmF1KdaIyumCXhkgXH OA8AG6LX4YVC7FzoKpkD1R4rtFLnOykD/U1ZusSS1z8Fb4DbQ2t237nI9vCDD4IZIOxF 7M4Xcgshmd6krotXBEpbP7DCfjBN7XZPH6jjDcelMZCDBzZtJYaYc5/PYpCkbO2giv49 a2Xni1ihGyRuZPa7V1zMtORrNzzoFvVT74JQN1wgpZCD5PKPVQXq/6sSBIy+2FNB8K4J eyjA== X-Gm-Message-State: APjAAAUtWqJKcx51lXXhJFo3fcvkjwoYxvU2NJYCra1V6ss24/Mm6Zkm LYQRuA6MEyuJWjvdOyRSmVY= X-Google-Smtp-Source: APXvYqycS1tavTcFNGeIH3sac+IpJIyT0iqf8k0rqBEihdH9p0NKSi7fc9H7S654uZDQCEBaoAqsAw== X-Received: by 2002:a17:902:bb88:: with SMTP id m8mr1458475pls.63.1582850842025; Thu, 27 Feb 2020 16:47:22 -0800 (PST) Received: from phantasmagoria.svl.corp.google.com ([2620:15c:2c4:201:2b0a:8c1:6a84:1aa0]) by smtp.gmail.com with ESMTPSA id e4sm4525500pfi.99.2020.02.27.16.47.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2020 16:47:21 -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 mm 2/2] mm: vm_insert_pages() checks if pte_index defined. Date: Thu, 27 Feb 2020 16:46:57 -0800 Message-Id: <20200228004657.79943-2-arjunroy.kdev@gmail.com> X-Mailer: git-send-email 2.25.1.481.gfbce0eb801-goog In-Reply-To: <20200228004657.79943-1-arjunroy.kdev@gmail.com> References: <20200228004657.79943-1-arjunroy.kdev@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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. Signed-off-by: Arjun Roy --- mm/memory.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/mm/memory.c b/mm/memory.c index d6f834f7d145..33631a5b5c3f 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1500,8 +1500,9 @@ static int insert_page(struct vm_area_struct *vma, = unsigned long addr, return retval; } =20 +#ifdef pte_index /* 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 =3D remaining_pages_total; return ret; } +#endif /* ifdef pte_index */ =20 /** * vm_insert_pages - insert multiple pages into user vma, batching the p= md 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 =3D addr + (*num * PAGE_SIZE) - 1; =20 if (addr < vma->vm_start || end_addr >=3D vma->vm_end) @@ -1586,6 +1589,18 @@ int vm_insert_pages(struct vm_area_struct *vma, un= signed 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 =3D 0, pgcount =3D *num; + int err; + + for (; idx < pgcount; ++idx) { + err =3D vm_insert_page(vma, addr + (PAGE_SIZE * idx), pages[idx]); + if (err) + break; + } + *num =3D pgcount - idx; + return err; +#endif /* ifdef pte_index */ } EXPORT_SYMBOL(vm_insert_pages); =20 --=20 2.25.1.481.gfbce0eb801-goog