Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp2469299rdb; Wed, 15 Nov 2023 01:21:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IGAf8LQORX+HqO14j/6S83HxZ1rkQQWGb8RdNpEndJi8JT6b/P0wCLG8VwhNZGxmWt0C9SO X-Received: by 2002:aa7:939a:0:b0:6be:308:e61b with SMTP id t26-20020aa7939a000000b006be0308e61bmr9892185pfe.10.1700040081885; Wed, 15 Nov 2023 01:21:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700040081; cv=none; d=google.com; s=arc-20160816; b=j0gTkaAtJSOu4LmYvp0a+snCUi116p6IG4FagE40iQrM1uFXxHm4Z57W4lqU3KXKTi +tX1wf3H9jDq9nk/2S9eLKhTJUqnrWfLNiMVDg8WcBZ6vg0YjwORNZVD7DAsFjFObm2A P4dPh28Z2LwmgbtGZ0llAyBTgeJYgbYkQ3RKgQ5Aw3ShuQeY6fWMk1/+C4DAbbZUK/4x PorAJguqzj1p5RU4oVr60GGgnSrIF2sc/RqYdhYcj7wwWV0rmlMAhWtnlfgDFoBs6PMT X9WQ6sDiqaNdTBybwyLa/OTX7nH+gv8T9mbHp67c3hO0v4UUomQU9Tj2wH2OjSkjohXB r3Xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=fcFUZa+OxVcMqVssDVCLudOoaSxMr168F1svsxSBhqw=; fh=IxiQEIQGPENdJTLCxCr8OlocWkBK4nqB4VMk5hvMCN8=; b=iZPXifKhojKQonH70QSIJ5SBTWdkg6s4UOBNV3HSIqxzpvL2GuNPgX+yBu6GFfkDt5 M9UGFCrsKsXwXYHkQZ1gHFConiGi903vXrTm60COA5iZFtIexfLscJMnc/LRG1I7osFu 3hLL3DFTb7FpTKTP0npaZ+0eH37oChrepIpjcStRyfWb/g/fmW3lzDYFXCYQmdJxeXRb GFXQ0f/U8+j4IuCPOT92QAcQT27dGfrCfZNTEREKumWzq/Gej/6yIoN1p1/1YQ+8r/Mx Cizkg3fcAzkUA0nQVqhJkEhtXWuIwayM93XMwuJEh0b6IWHuGRdILsQ1ujQ5qo8iWfrx 7KYw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id ca42-20020a056a0206aa00b005be3683ec6asi10693482pgb.184.2023.11.15.01.21.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 01:21:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 438638075EEF; Wed, 15 Nov 2023 01:21:19 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234695AbjKOJVK (ORCPT + 99 others); Wed, 15 Nov 2023 04:21:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234684AbjKOJVI (ORCPT ); Wed, 15 Nov 2023 04:21:08 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08E1EFC; Wed, 15 Nov 2023 01:21:04 -0800 (PST) Received: from dggpemm500005.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SVcyG45DXzmXDl; Wed, 15 Nov 2023 17:17:42 +0800 (CST) Received: from [10.69.30.204] (10.69.30.204) by dggpemm500005.china.huawei.com (7.185.36.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Wed, 15 Nov 2023 17:21:02 +0800 Subject: Re: [PATCH RFC 3/8] memory-provider: dmabuf devmem memory provider To: Jason Gunthorpe , Mina Almasry CC: Jakub Kicinski , , , , , Willem de Bruijn , Kaiyuan Zhang , Jesper Dangaard Brouer , Ilias Apalodimas , Eric Dumazet , =?UTF-8?Q?Christian_K=c3=b6nig?= , Matthew Wilcox , Linux-MM References: <20231113130041.58124-1-linyunsheng@huawei.com> <20231113130041.58124-4-linyunsheng@huawei.com> <20231113180554.1d1c6b1a@kernel.org> <0c39bd57-5d67-3255-9da2-3f3194ee5a66@huawei.com> From: Yunsheng Lin Message-ID: Date: Wed, 15 Nov 2023 17:21:02 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.69.30.204] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500005.china.huawei.com (7.185.36.74) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.5 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 15 Nov 2023 01:21:19 -0800 (PST) On 2023/11/14 21:16, Jason Gunthorpe wrote: > On Tue, Nov 14, 2023 at 04:21:26AM -0800, Mina Almasry wrote: > >> Actually because you put the 'strtuct page for devmem' in >> skb->bv_frag, the net stack will grab the 'struct page' for devmem >> using skb_frag_page() then call things like page_address(), kmap, >> get_page, put_page, etc, etc, etc. > > Yikes, please no. If net has its own struct page look alike it has to > stay entirely inside net. A non-mm owned struct page should not be > passed into mm calls. It is just way too hacky to be seriously > considered :( Yes, that is something this patchset is trying to do, defining its own struct page look alike for page pool to support devmem. struct page for devmem will not be called into the mm subsystem, so most of the mm calls is avoided by calling into the devmem memory provider' ops instead of calling mm calls. As far as I see for now, only page_ref_count(), page_is_pfmemalloc() and PageTail() is called for devmem page, which should be easy to ensure that those call for devmem page is consistent with the struct page owned by mm. I am not sure if we can use some kind of compile/runtime checking to ensure those kinds of consistency? > >>> I would expect net stack, page pool, driver still see the 'struct page', >>> only memory provider see the specific struct for itself, for the above, >>> devmem memory provider sees the 'struct page_pool_iov'. >>> >>> The reason I still expect driver to see the 'struct page' is that driver >>> will still need to support normal memory besides devmem. > > I wouldn't say this approach is unreasonable, but it does have to be > done carefully to isolate the mm. Keeping the struct page in the API > is going to make this very hard. I would expect that most of the isolation is done in page pool, as far as I can see: 1. For control part: the driver may need to tell the page pool which memory provider it want to use. Or the administrator specifies which memory provider to use by some netlink-based cmd. 2. For data part: I am thinking that driver should only call page_pool_alloc(), page_pool_free() and page_pool_get_dma_addr related function. Of course the driver may need to be aware of that if it can call kmap() or page_address() on the page returned from page_pool_alloc(), and maybe tell net stack that those pages is not kmap()'able and page_address()'able. > > Jason > . >