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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A731EB64DD for ; Mon, 17 Jul 2023 02:28:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230469AbjGQC25 (ORCPT ); Sun, 16 Jul 2023 22:28:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229461AbjGQC2z (ORCPT ); Sun, 16 Jul 2023 22:28:55 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3787F12B; Sun, 16 Jul 2023 19:28:54 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4R45XX5VW8zNmPN; Mon, 17 Jul 2023 10:25:32 +0800 (CST) Received: from [10.174.151.185] (10.174.151.185) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Mon, 17 Jul 2023 10:28:51 +0800 Subject: Re: [PATCH] mm/memcg: use get_page() for device private pages in mc_handle_swap_pte() To: Matthew Wilcox CC: , , , , , , , , References: <20230715032802.2508163-1-linmiaohe@huawei.com> From: Miaohe Lin Message-ID: <73b5d7c2-783d-3d75-2c1b-4b91a039df94@huawei.com> Date: Mon, 17 Jul 2023 10:28:50 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.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.174.151.185] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2023/7/15 11:56, Matthew Wilcox wrote: > On Sat, Jul 15, 2023 at 11:28:02AM +0800, Miaohe Lin wrote: >> When page table locked is held, the page can't be freed from under us. > > But the page isn't mapped into the page table ... there's a swap entry > in the page table, so I don't think your logic holds. > IIUC, device_private_entry will hold one page refcnt when it's set to page table. And there's similar code in do_swap_page(): vm_fault_t do_swap_page(struct vm_fault *vmf) if (unlikely(non_swap_entry(entry))) { if (is_device_private_entry(entry)) /* * Get a page reference while we know the page can't be * freed. */ get_page(vmf->page); pte_unmap_unlock(vmf->pte, vmf->ptl); ret = vmf->page->pgmap->ops->migrate_to_ram(vmf); put_page(vmf->page); ... If my logic doesn't hold, do_swap_page() will need to fix the code. Or am I miss something? Thanks Matthew.