Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2759561pxb; Mon, 19 Apr 2021 13:12:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxEE9GymmooQzBVVrdPuNkzDV5t6B8neQzS1R4uozay4TI+YdqQRSpYXsJeztTuKNOsCrjd X-Received: by 2002:a05:6402:b41:: with SMTP id bx1mr10348890edb.105.1618863169312; Mon, 19 Apr 2021 13:12:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618863169; cv=none; d=google.com; s=arc-20160816; b=K/aoHtTzCnksW0FgmlgwUYEDgII0Kp4m76YO/FqFiT27CksyS5cSNuoD7ix87/YOAY LMP2wjwg4YWsI2fOX4sD555fMwy7kFMXxWJBT/5LAaSEwH0WZiJUhQ0gOt0OszhD0HTQ PBPfKvPIGcC00YNzlorGlecuAWY9kGMD6gwyiLP1/WY8h0+LrxoCXqT0L4CRZ0LIoFmN WiGvc1V5lWgcanEXLGCPOa0utSeyenGzDKmMoJYfosHfMnXff16R3jhw6lE9ix1sD6iL wAQrc5t2nmclR0I+6pW2l2UL/H8zM159M6Q5PaKz9gnpJJ0Ycrk77D55EhRzyZONNuak g5yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=O961I/6SpeSlE/psbTVuCjUHNPMleqN4PCYNj9U2q7A=; b=LSvXzZUmnLEkzH6RWmkU/vZEU0CXMDADeCUf21HXgKxErHcskvtY9HMWBIFxf+o8Z6 1i98J5wq3gxk/4MQZbtwpnqvlbJ/gwP4nZS6OOilceyTHAj/CL5pcIF647Xm0L5O+j7u B8JNE4P4s9dAGQrchPO5sKJmzJkL4wEoOGFUqJ7cdYB3Mrui2WYM0MtHZIk5WbtIpDfK g0SJXZbqXs5PPboYyBjq1KrhkM3xLnI75/zMXWcTbnt/XYdTrzXxunLt8ES+OWo213kV 1MrVI6QLPWSlL3mTkrqIXVdTTkD8bJVv5lc99v+o+UJ8SdC3M386YD3961dBdukhgD4z RwVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=QyCXioim; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dn3si7324304ejc.68.2021.04.19.13.12.25; Mon, 19 Apr 2021 13:12:49 -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=@google.com header.s=20161025 header.b=QyCXioim; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238497AbhDSQWn (ORCPT + 99 others); Mon, 19 Apr 2021 12:22:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233989AbhDSQWj (ORCPT ); Mon, 19 Apr 2021 12:22:39 -0400 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E0BBC061763 for ; Mon, 19 Apr 2021 09:22:09 -0700 (PDT) Received: by mail-lf1-x132.google.com with SMTP id i10so20993680lfe.11 for ; Mon, 19 Apr 2021 09:22:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=O961I/6SpeSlE/psbTVuCjUHNPMleqN4PCYNj9U2q7A=; b=QyCXioim+uvs6ZsZ5HXYH8805X6eZVpFOsRXDPDu0FhkLM2j9m+7VBhsbXtQ60iw90 VG4CzcSNws5VKEnnaLwaE+Mla8FPUF4Ifo/aduTqVEEsqkEIHDsv7++Nb8PAs+zX9RJs l4FvqPnoAc6U8fzSYX23GNIlLVFESDEdeZw4ASgibwICAnAA31uQArRchuzLd7XpCmqY MplUe6zFqDWDRPswRq04ECp9Kdz+N7Fihf5+eX9D+hxKcWBqFD4iHE/tYp91Yr2laL1W 4GCuRoeQb17je7gyDNL69BxZQAhg2z1g3kNu32/o4rF6quRGBe/h8EnLEcbHG1UhK1rf DaiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=O961I/6SpeSlE/psbTVuCjUHNPMleqN4PCYNj9U2q7A=; b=beeWrOphZ3P3kxDqYssXyS6o/juHh0FPJHF7oNNhynmTrlRB3Cx4lZa2Cr72WxVhR9 SXRpuf7wtgOLSS4EktdayVzeji4IfwEPFYiphMK91I3dQZz1gyk+qcXTAD7usomalbFQ 6PgRnb202BumC3oHJAYVySRkax4d2n1YzmfDkKPMhRFaKQiOhJBeSxW2WN99E7SCer+X 5VJ7eR+dbf69SaSBlq+KlpSEMA7deCT3wKjmfTRisfAAf5gMGaKlEOG3O/UbEzUUUEnY H3zBlUADG4KkS9nya1EV9wdNoGDbFYXELT38iLmGs0ly4iCxHkFetMLfEFtTkRYILq9F oxAg== X-Gm-Message-State: AOAM532haaWFWph1o6oKD9p8xPMCpP81lApbkiCG5b+zX2qhSIsCIGr+ HRF4R4uSzR0jLtlQa9dcFMcAD99Yh+E1wnain+Pt+g== X-Received: by 2002:ac2:58d9:: with SMTP id u25mr3133485lfo.117.1618849327780; Mon, 19 Apr 2021 09:22:07 -0700 (PDT) MIME-Version: 1.0 References: <20210409223801.104657-1-mcroce@linux.microsoft.com> <20210409223801.104657-3-mcroce@linux.microsoft.com> <20210410154824.GZ2531743@casper.infradead.org> <20210414214132.74f721dd@carbon> In-Reply-To: From: Shakeel Butt Date: Mon, 19 Apr 2021 09:21:55 -0700 Message-ID: Subject: Re: [PATCH net-next v3 2/5] mm: add a signature in struct page To: Ilias Apalodimas 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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/