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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 F3F9DC433ED for ; Wed, 5 May 2021 16:04:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8A31E613B3 for ; Wed, 5 May 2021 16:04:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8A31E613B3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E643C6B0071; Wed, 5 May 2021 12:04:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E13936B0073; Wed, 5 May 2021 12:04:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CDBE76B0074; Wed, 5 May 2021 12:04:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0216.hostedemail.com [216.40.44.216]) by kanga.kvack.org (Postfix) with ESMTP id AF2606B0071 for ; Wed, 5 May 2021 12:04:51 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 648625DDB for ; Wed, 5 May 2021 16:04:51 +0000 (UTC) X-FDA: 78107650782.14.576061F Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf29.hostedemail.com (Postfix) with ESMTP id A8A673F1 for ; Wed, 5 May 2021 16:04:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=ruJMZgf1MOFrHiDvESe412bw0xTvpBkcG4kkfAZLeaU=; b=vqG2v2EXyQGrKoSpj5ZhAol8Og mXo8O37ehL+aQQeN9HbjeaNnNFx8Ww1h+jFXt8p6zHN4eLE9UYUucRJ6iFa/rn7/6KSnFeaAxvt8f 9PS1AoNDWXHVQO4Gxikdl41K8gW/Dn6WI5En7iBwCA4Wvcy953NvijioqSGihnFVdNxUoX88LnsSS gXWSYwE1me65tCCzc1hEsdSlQmBhVW5eTvTLddQrgEoTfRgPJI1ILPKKjbeciQiUWfQU49nV+0Lcm o8Q8xR6ezD14DYIfZXGbHD0KtnUAsF/lToxSKUJ86yITs/KjBwnEG3r9BRgvKZPBxULcNoO8rjj7z nhzrr61w==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1leJyP-000YhJ-Ef; Wed, 05 May 2021 16:02:25 +0000 From: "Matthew Wilcox (Oracle)" To: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-kernel@vger.kernel.org Subject: [PATCH v9 45/96] mm: Add kmap_local_folio Date: Wed, 5 May 2021 16:05:37 +0100 Message-Id: <20210505150628.111735-46-willy@infradead.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210505150628.111735-1-willy@infradead.org> References: <20210505150628.111735-1-willy@infradead.org> MIME-Version: 1.0 Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=vqG2v2EX; spf=none (imf29.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: A8A673F1 X-Stat-Signature: x1gwompsfhgmm8xn7t8199brsj77yrjt Received-SPF: none (infradead.org>: No applicable sender policy available) receiver=imf29; identity=mailfrom; envelope-from=""; helo=casper.infradead.org; client-ip=90.155.50.34 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1620230685-254319 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: This allows us to map a portion of a folio. Callers can only expect to access up to the next page boundary. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/highmem-internal.h | 11 +++++++++ include/linux/highmem.h | 38 ++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/include/linux/highmem-internal.h b/include/linux/highmem-int= ernal.h index 7902c7d8b55f..39cdcfdbc23a 100644 --- a/include/linux/highmem-internal.h +++ b/include/linux/highmem-internal.h @@ -73,6 +73,12 @@ static inline void *kmap_local_page(struct page *page) return __kmap_local_page_prot(page, kmap_prot); } =20 +static inline void *kmap_local_folio(struct folio *folio, size_t offset) +{ + struct page *page =3D nth_page(&folio->page, offset / PAGE_SIZE); + return __kmap_local_page_prot(page, kmap_prot) + offset % PAGE_SIZE; +} + static inline void *kmap_local_page_prot(struct page *page, pgprot_t pro= t) { return __kmap_local_page_prot(page, prot); @@ -160,6 +166,11 @@ static inline void *kmap_local_page(struct page *pag= e) return page_address(page); } =20 +static inline void *kmap_local_folio(struct folio *folio, size_t offset) +{ + return page_address(&folio->page) + offset; +} + static inline void *kmap_local_page_prot(struct page *page, pgprot_t pro= t) { return kmap_local_page(page); diff --git a/include/linux/highmem.h b/include/linux/highmem.h index b06eeeaee975..b01deb45d265 100644 --- a/include/linux/highmem.h +++ b/include/linux/highmem.h @@ -96,6 +96,44 @@ static inline void kmap_flush_unused(void); */ static inline void *kmap_local_page(struct page *page); =20 +/** + * kmap_local_folio - Map a page in this folio for temporary usage + * @folio: The folio to be mapped. + * @offset: The byte offset within the folio. + * + * Returns: The virtual address of the mapping + * + * Can be invoked from any context. + * + * Requires careful handling when nesting multiple mappings because the = map + * management is stack based. The unmap has to be in the reverse order o= f + * the map operation: + * + * addr1 =3D kmap_local_folio(page1, offset1); + * addr2 =3D kmap_local_folio(page2, offset2); + * ... + * kunmap_local(addr2); + * kunmap_local(addr1); + * + * Unmapping addr1 before addr2 is invalid and causes malfunction. + * + * Contrary to kmap() mappings the mapping is only valid in the context = of + * the caller and cannot be handed to other contexts. + * + * On CONFIG_HIGHMEM=3Dn kernels and for low memory pages this returns t= he + * virtual address of the direct mapping. Only real highmem pages are + * temporarily mapped. + * + * While it is significantly faster than kmap() for the higmem case it + * comes with restrictions about the pointer validity. Only use when rea= lly + * necessary. + * + * On HIGHMEM enabled systems mapping a highmem page has the side effect= of + * disabling migration in order to keep the virtual address stable acros= s + * preemption. No caller of kmap_local_folio() can rely on this side eff= ect. + */ +static inline void *kmap_local_folio(struct folio *folio, size_t offset)= ; + /** * kmap_atomic - Atomically map a page for temporary usage - Deprecated! * @page: Pointer to the page to be mapped --=20 2.30.2