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=-8.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS 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 70FF1C12002 for ; Wed, 21 Jul 2021 15:02:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DFF176120E for ; Wed, 21 Jul 2021 15:02:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DFF176120E 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 6D8536B0089; Wed, 21 Jul 2021 11:02:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6618D6B008A; Wed, 21 Jul 2021 11:02:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 528E86B008C; Wed, 21 Jul 2021 11:02:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0245.hostedemail.com [216.40.44.245]) by kanga.kvack.org (Postfix) with ESMTP id 331EE6B0089 for ; Wed, 21 Jul 2021 11:02:31 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id D4482248BB for ; Wed, 21 Jul 2021 15:02:30 +0000 (UTC) X-FDA: 78386911260.13.DB9CAB5 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf16.hostedemail.com (Postfix) with ESMTP id B7A9BF000EE6 for ; Wed, 21 Jul 2021 15:02:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=36rD6Wb6Yd/QwjBFd0xntesjrDvCLO/ZMPTZtTD0QUg=; b=IbAsiplG3kaBoKMtU7f2oPHIkK 5dlac78FL49HMshsrcmvadPy1WmsH18q106Jpb+Iee7TQCqlyesdsEivr4A+9de5In08wYaD60kV3 aREeTdRGTpwoQLzIHAe5QO6jzOThu2wCuUF4UCC6eW7w8I2liXJ2Xhr8+VS4ZARCwDf/tZB6K4B32 /8YoqTPTNIqUuA4wrAQr2sVmliK0aY17e9w6lgoAmB2ymku1YrsbFpqoXB40WHYlzF9Jnxeb4Ri5b JfHtjcepGm1lA8OilRECyGF/A460xIrBYxJE7PjPO5zcahBURWNuhONWHRksJUnfoj0aR7uELh3rU 4c081oQw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1m6Djb-009JG6-8B; Wed, 21 Jul 2021 15:02:11 +0000 Date: Wed, 21 Jul 2021 16:02:07 +0100 From: Matthew Wilcox To: Mike Rapoport Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Christoph Hellwig Subject: Re: [PATCH v14 054/138] mm: Add kmap_local_folio() Message-ID: References: <20210715033704.692967-1-willy@infradead.org> <20210715033704.692967-55-willy@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=IbAsiplG; spf=none (imf16.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: rspam03 X-Rspamd-Queue-Id: B7A9BF000EE6 X-Stat-Signature: su3z1jy89oxbacrsii48ui1447dseyg7 X-HE-Tag: 1626879741-538367 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: On Wed, Jul 21, 2021 at 05:22:16PM +0300, Mike Rapoport wrote: > On Wed, Jul 21, 2021 at 03:12:03PM +0100, Matthew Wilcox wrote: > > On Wed, Jul 21, 2021 at 12:58:24PM +0300, Mike Rapoport wrote: > > > > +/** > > > > + * 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. > > > > > > Context: 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 of > > > > + * the map operation: > > > > + * > > > > + * addr1 = kmap_local_folio(page1, offset1); > > > > + * addr2 = kmap_local_folio(page2, offset2); > > > > > > Please s/page/folio/g here and in the description below > > > > > > > + * ... > > > > + * 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=n kernels and for low memory pages this returns the > > > > + * 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 really > > > > + * necessary. > > > > + * > > > > + * On HIGHMEM enabled systems mapping a highmem page has the side effect of > > > > + * disabling migration in order to keep the virtual address stable across > > > > + * preemption. No caller of kmap_local_folio() can rely on this side effect. > > > > + */ > > > > kmap_local_folio() only maps one page from the folio. So it's not > > appropriate to s/page/folio/g. I fiddled with the description a bit to > > make this clearer: > > > > /** > > * 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. > > + * @folio: The folio containing the page. > > + * @offset: The byte offset within the folio which identifies the page. > > * > > * Requires careful handling when nesting multiple mappings because the map > > * management is stack based. The unmap has to be in the reverse order of > > * the map operation: > > * > > - * addr1 = kmap_local_folio(page1, offset1); > > - * addr2 = kmap_local_folio(page2, offset2); > > + * addr1 = kmap_local_folio(folio1, offset1); > > + * addr2 = kmap_local_folio(folio2, offset2); > > * ... > > * kunmap_local(addr2); > > * kunmap_local(addr1); > > @@ -131,6 +127,9 @@ static inline void *kmap_local_page(struct page *page); > > * On HIGHMEM enabled systems mapping a highmem page has the side effect of > > * disabling migration in order to keep the virtual address stable across > > * preemption. No caller of kmap_local_folio() can rely on this side effect. > > + * > > + * Context: Can be invoked from any context. > > + * Return: The virtual address of @offset. > > */ > > static inline void *kmap_local_folio(struct folio *folio, size_t offset) > > This is clearer, thanks! > > Maybe just add page to Return: description: > > * Return: The virtual address of page @offset. No, it really does return the virtual address of @offset. If you ask for offset 0x1234 within a (sufficiently large) folio, it will map the second page of that folio and return the address of the 0x234'th byte within it.