Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5729586pxv; Wed, 21 Jul 2021 12:28:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyi+HINlQ11W+RF2SMzOBHGfx7wW04exaUqpKSImlxCywzVSVxXCADrsOt2ECTmuaciciio X-Received: by 2002:a5d:87cc:: with SMTP id q12mr27775637ios.131.1626895723533; Wed, 21 Jul 2021 12:28:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626895723; cv=none; d=google.com; s=arc-20160816; b=AfkY3tVHLZKToNd/jOvmKzy4mw3xxlNyZ4I9J+WkWD/oMmIh/ZVyDMAeaksfsgEUnj g8wabMBn/tB/roYo8HQsVHTQ4jJNhRitXgTO0X1kqCTuBHM6AdiVF1L8wXb2/+H01b7L z6CnyRc8LwnlxtZ/pZq4FttHUTxCLgrQ556pluVimr751sCt0h2S+f2qrul0ASkisDNG n+JURGRvjhQndPwLFjGJNfI38MMmoqNS3AXAvEJQtWSH3RqNaVQdRc76AbFtfrff7yFL +/89IGaQsN8gB8nhsr7+866KjifUlnGYteftm38dJaVnyuLEWU/EbVeYjZOYhMqqhuk+ cVoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=36rD6Wb6Yd/QwjBFd0xntesjrDvCLO/ZMPTZtTD0QUg=; b=cu65a777ZaSwjpQ7dQ1mS3n7AnEqMLjbk+EjWTj+nR4Lw+D9JmAbnhzo0a62f9b5Mp RiuLsKEOv6EQ/0h6j3LMNiALjLIdsiw5/pynYdGMN3M/KRt62uRqhv/NkKA+58IWcI6R fosLwWM4mT6gR9TqjnHhE4tL+Qy/jehdUzmQFeT1wgTCXKHsmYOfT3REfoG2S642fh42 Kx578lcVcUZKlDHxmglciVe42Qcm2xa0/8U9/QAzOwHV4nQndVuQ+IwZn1O/KpallLJe xj173X8B8jFiQ5BcOKno0Vo99rRxCTWylvh6ZibLcchvoEkyFUufv+Vn74Xs20EaDslh Y/Mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=IbAsiplG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f10si32511648ila.58.2021.07.21.12.28.32; Wed, 21 Jul 2021 12:28:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=IbAsiplG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239634AbhGUOX4 (ORCPT + 99 others); Wed, 21 Jul 2021 10:23:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239510AbhGUOVr (ORCPT ); Wed, 21 Jul 2021 10:21:47 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76376C061575; Wed, 21 Jul 2021 08:02:17 -0700 (PDT) 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: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.