Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2826163pxb; Mon, 19 Apr 2021 15:15:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwt36dIffn5Vga0XjBflOhhnIuy/JLi8BcYqPczEwx7Y11pMxpgU8H8xdep+M95SCPZdx3A X-Received: by 2002:a63:3812:: with SMTP id f18mr13921933pga.380.1618870531395; Mon, 19 Apr 2021 15:15:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618870531; cv=none; d=google.com; s=arc-20160816; b=e9E8k0cnH9mkCZLWdFb9LYENGejKKej0rxLCX1aUvwg07Wir5higHIwp2Gup+ejbm3 1mySeHEzyAiq3cR1nfGnNsKiGdWrgBunI3xd5tVGzC27ZNSrQviOk8ysi7hOyuEh+dGj k71SHaSBlo8tBdgW5UDEzo2Ak00vqmFA9g5Y0KyQpPW0iZeBrBrwK5rXnxlUzSCMWsId vmgTXuF1vX0VB7tBBXoWBOP9OU8XVvonFUSq2bFhSrdvastxCZOD1KCc5eQ5Qw9XDVy3 sRj5kCCq6UZ4BFaCI3bDIQJA8TJJ5PS7EqFcuNnZg978EhH/+oqOn+GwKV/lthqruFeX FqXA== 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=3TXXauaxjaFJkryZmKe4pKXsqt2c2W4efv7xXXt6kDg=; b=qFYOE4pAk7+mPecInQ0P9Cd0TwHD6cZsGiDB+mG5VjzQaq66G1dIHkrItSRsdjp4sh Zxmt8sOQpFkSeuhOV+klwIp4e+gglGCCkev4H2BNBnvBts1b4Kyfep+n54QAxo34hRno Z229mlf5Du1z1eoGId0eGSRTW3EqtDqgYTh2HXytXHjhIwlCo3QWXh47JL0Q1z7R8zka iF59vyg9eDfOPHU/08E2XND+QBaqWw9xH002wGbhUlgLV7mnsnsyQIVJJC7lXZyr4EJa ogvaDcKDTvpFS7/UIIzfKCUV7AR33FxGd796FdAqFhWudNKawNDrVhSJV21dKJojH1AB p7/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="K9U3Wsn/"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i11si19402133pgs.125.2021.04.19.15.15.19; Mon, 19 Apr 2021 15:15:31 -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=@linaro.org header.s=google header.b="K9U3Wsn/"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238973AbhDSSln (ORCPT + 99 others); Mon, 19 Apr 2021 14:41:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234608AbhDSSlk (ORCPT ); Mon, 19 Apr 2021 14:41:40 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C34BC061763 for ; Mon, 19 Apr 2021 11:41:10 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id x12so33716576ejc.1 for ; Mon, 19 Apr 2021 11:41:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=3TXXauaxjaFJkryZmKe4pKXsqt2c2W4efv7xXXt6kDg=; b=K9U3Wsn/ZMp1qcVYmH8K49eGtKmxmMFJSG/7TwpdB++O51Bvwx+tGQzCMd2HWtCCCj XkCNqHebmllrUDYH703DvaCBFIWgSQv6LE4Cbcf2HP99jSESzpqew5uPUVaK2069tqYj tZYbGjtxJ2VsQp+eM/Xqdg32vwrRUqYHp41rtvTo2tv49YUNJF97ZV4gpkqaEDa1JKZL Z6YVtkJSH7bYpmUle6fdm8FVq4JLc6chNiBFVgFpOGNZ+D9JgQikxIFy4njTKnuu92mH pS/DzlQqFeg0jYG6YLidrAmH1WKQgCm7dvMcSnuxGhhjUn59EuYG3vW+H+LmrqEFQqyA 83cA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=3TXXauaxjaFJkryZmKe4pKXsqt2c2W4efv7xXXt6kDg=; b=EjsLS6M/l9aeFzS8huB96LFh6Kz+iBfD8oBNFwf5dT2WJhrPUpNEv7Qk/NmPmtUf5j bJORFV/vX+Vumd9P9xYVpxmJQY4OFx4YDTDhTAdG4vWrvEE7KZYOS6Axja6fmxH0bpmR nEq33sux0mT+OnVnhZCp666KI7JW/O2HGNpDWnaLAw2nhFpp1rGXirY2rvbJD9UyP2/X pVszKtx+ngyH7jaLlPUBU0nUoOtEzsxIkYJROC2+cK1EW348o161sWweK5aRljOGBwtk Qait3EVObPHv1EFbawM2VJNKEcEt05j6kvgeMMxfdi5uxdzwboWu3RoeB8lg8p07+c2F F6CQ== X-Gm-Message-State: AOAM531MGB2RisRR9Bs0U4ZlqeutUD8EGpl8rXu4/Fo726aTAKeiIjRC FiyJuRug91Js5+xV3gF5KUyD3w== X-Received: by 2002:a17:906:6896:: with SMTP id n22mr23676314ejr.316.1618857669049; Mon, 19 Apr 2021 11:41:09 -0700 (PDT) Received: from apalos.home (ppp-94-65-92-88.home.otenet.gr. [94.65.92.88]) by smtp.gmail.com with ESMTPSA id l6sm5233811ejc.92.2021.04.19.11.41.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Apr 2021 11:41:08 -0700 (PDT) Date: Mon, 19 Apr 2021 21:41:02 +0300 From: Ilias Apalodimas To: Shakeel Butt Cc: Jesper Dangaard Brouer , Matthew Wilcox , Matteo Croce , netdev , Linux MM , Ayush Sawal , Vinay Kumar Yadav , Rohit Maheshwari , "David S. Miller" , Jakub Kicinski , Thomas Petazzoni , Marcin Wojtas , Russell King , Mirko Lindner , Stephen Hemminger , Tariq Toukan , Jesper Dangaard Brouer , Alexei Starovoitov , Daniel Borkmann , John Fastabend , Boris Pismenny , Arnd Bergmann , Andrew Morton , "Peter Zijlstra (Intel)" , Vlastimil Babka , Yu Zhao , Will Deacon , Michel Lespinasse , Fenghua Yu , Roman Gushchin , Hugh Dickins , Peter Xu , Jason Gunthorpe , Guoqing Jiang , Jonathan Lemon , Alexander Lobakin , Cong Wang , wenxu , Kevin Hao , Aleksandr Nogikh , Jakub Sitnicki , Marco Elver , Willem de Bruijn , Miaohe Lin , Yunsheng Lin , Guillaume Nault , LKML , linux-rdma@vger.kernel.org, bpf , Eric Dumazet , David Ahern , Lorenzo Bianconi , Saeed Mahameed , Andrew Lunn , Paolo Abeni Subject: Re: [PATCH net-next v3 2/5] mm: add a signature in struct page Message-ID: References: <20210410154824.GZ2531743@casper.infradead.org> <20210414214132.74f721dd@carbon> 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 Mon, Apr 19, 2021 at 09:21:55AM -0700, Shakeel Butt wrote: > On Mon, Apr 19, 2021 at 8:43 AM Ilias Apalodimas > wrote: > > > [...] > > > Pages mapped into the userspace have their refcnt elevated, so the > > > page_ref_count() check by the drivers indicates to not reuse such > > > pages. > > > > > > > When tcp_zerocopy_receive() is invoked it will call tcp_zerocopy_vm_insert_batch() > > which will end up doing a get_page(). > > What you are saying is that once the zerocopy is done though, skb_release_data() > > won't be called, but instead put_page() will be? If that's the case then we are > > indeed leaking DMA mappings and memory. That sounds weird though, since the > > refcnt will be one in that case (zerocopy will do +1/-1 once it's done), so who > > eventually frees the page? > > If kfree_skb() (or any wrapper that calls skb_release_data()) is called > > eventually, we'll end up properly recycling the page into our pool. > > > > From what I understand (Eric, please correct me if I'm wrong) for > simple cases there are 3 page references taken. One by the driver, > second by skb and third by page table. > > In tcp_zerocopy_receive(), tcp_zerocopy_vm_insert_batch() gets one > page ref through insert_page_into_pte_locked(). However before > returning from tcp_zerocopy_receive(), the skb references are dropped > through tcp_recv_skb(). So, whenever the user unmaps the page and > drops the page ref only then that page can be reused by the driver. > > In my understanding, for zerocopy rx the skb_release_data() is called > on the pages while they are still mapped into the userspace. So, > skb_release_data() might not be the right place to recycle the page > for zerocopy. The email chain at [1] has some discussion on how to > bundle the recycling of pages with their lifetime. > > [1] https://lore.kernel.org/linux-mm/20210316013003.25271-1-arjunroy.kdev@gmail.com/ Ah right, you mentioned the same email before and I completely forgot about it! In the past we had thoughts of 'stealing' the page on put_page instead of skb_release_data(). We were afraid that this would cause a measurable performance hit, so we tried to limit it within the skb lifecycle. However I don't think this will be a problem. Assuming we are right here and skb_release_data() is called while the userspace holds an extra reference from the mapping here's what will happen: skb_release_data() -> skb_free_head() -> page_pool_return_skb_page() -> set_page_private() -> xdp_return_skb_frame() -> __xdp_return() -> page_pool_put_full_page() -> page_pool_put_page() -> __page_pool_put_page() When we call __page_pool_put_page(), the refcnt will be != 1 (because a user mapping is still active), so we won't try to recycle it. Instead we'll remove the DMA mappings and decrease the refcnt. So although the recycling won't 'work', nothing bad will happen (famous last words). In any case, I'll double check with the test you pointed out before v4. Thanks! /Ilias