From patchwork Fri Oct 9 21:59:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralph Campbell X-Patchwork-Id: 11829711 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 08E6815E6 for ; Fri, 9 Oct 2020 22:00:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9B5E42225B for ; Fri, 9 Oct 2020 22:00:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="GeXxS06C" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9B5E42225B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B74C48E0003; Fri, 9 Oct 2020 18:00:53 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B255E8E0001; Fri, 9 Oct 2020 18:00:53 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A3B0A8E0003; Fri, 9 Oct 2020 18:00:53 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0059.hostedemail.com [216.40.44.59]) by kanga.kvack.org (Postfix) with ESMTP id 73E038E0001 for ; Fri, 9 Oct 2020 18:00:53 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 07AAD8249980 for ; Fri, 9 Oct 2020 22:00:53 +0000 (UTC) X-FDA: 77353757586.09.shop62_5e01b19271e4 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin09.hostedemail.com (Postfix) with ESMTP id DE42C180AD806 for ; Fri, 9 Oct 2020 22:00:52 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,rcampbell@nvidia.com,,RULES_HIT:30012:30054:30064:30070,0,RBL:216.228.121.64:@nvidia.com:.lbl8.mailshell.net-64.10.201.10 62.18.0.100;04yra6ihgyfzk6wa78askc6f8gpcqyc1545d4we3ixhp3tcictfb7j8kbnmr8af.gkmu6ez4uck7kq1wogrro6zuxouw7jystotzj1jyu1r847utj89pfqwgzt5g94c.6-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: shop62_5e01b19271e4 X-Filterd-Recvd-Size: 3880 Received: from hqnvemgate25.nvidia.com (hqnvemgate25.nvidia.com [216.228.121.64]) by imf44.hostedemail.com (Postfix) with ESMTP for ; Fri, 9 Oct 2020 22:00:52 +0000 (UTC) Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Fri, 09 Oct 2020 14:59:53 -0700 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 9 Oct 2020 22:00:46 +0000 Received: from rcampbell-dev.nvidia.com (10.124.1.5) by mail.nvidia.com (172.20.187.12) with Microsoft SMTP Server id 15.0.1473.3 via Frontend Transport; Fri, 9 Oct 2020 22:00:46 +0000 From: Ralph Campbell To: , , CC: Johannes Weiner , Michal Hocko , Vladimir Davydov , =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , Balbir Singh , Ira Weiny , Andrew Morton , Ralph Campbell , Subject: [PATCH] mm/memcg: fix device private memcg accounting Date: Fri, 9 Oct 2020 14:59:52 -0700 Message-ID: <20201009215952.2726-1-rcampbell@nvidia.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-NVConfidentiality: public DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1602280794; bh=7mbqnLRSmP8gyFcv2CaKHAGuiDlEp5BFChE0DK1AomM=; h=From:To:CC:Subject:Date:Message-ID:X-Mailer:MIME-Version: X-NVConfidentiality:Content-Transfer-Encoding:Content-Type; b=GeXxS06CgAM4OOs4VCnOprIky8XoMeqlb13IWp0IGbvVpb7B8gd+hqzTalJC/zNQy wqBVq14+n5Sn4XP6sXOxEMREEzyaO7RQXpwh00B/1HXhMrUJXKm6747f8MNxqTAovl RMHcyxNBZo/hWbb4hatQSFNc2MqflrLJCFYTod+GkNE6Rm4eIOjVfeVKsgWm5pa0ta T0bUuVSRMbG740o3HCQ5e89pmK/+o+j31QFnM4S85NaLtML/52R0fzfQN3RHTsuJKT Y0Xg08kvpmukYGORsuuNmYdLYb4jE1bR00IypKYRojk7PVJADHRkW0mGzF4VnQCS1y +dRqbzURrmy8g== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The code in mc_handle_swap_pte() checks for non_swap_entry() and returns NULL before checking is_device_private_entry() so device private pages are never handled. Fix this by checking for non_swap_entry() after handling device private swap PTEs. Cc: stable@vger.kernel.org Fixes: c733a82874a7 ("mm/memcontrol: support MEMORY_DEVICE_PRIVATE") Signed-off-by: Ralph Campbell Acked-by: Johannes Weiner --- I'm not sure exactly how to test this. I ran the HMM self tests but that is a minimal sanity check. I think moving the self test from one memory cgroup to another while it is running would exercise this patch. I'm looking at how the test could move itself to another group after migrating some anonymous memory to the test driver. This applies cleanly to linux-5.9.0-rc8-mm1 and is for Andrew Morton's tree. mm/memcontrol.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 2636f8bad908..3a24e3b619f5 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5549,7 +5549,7 @@ static struct page *mc_handle_swap_pte(struct vm_area_struct *vma, struct page *page = NULL; swp_entry_t ent = pte_to_swp_entry(ptent); - if (!(mc.flags & MOVE_ANON) || non_swap_entry(ent)) + if (!(mc.flags & MOVE_ANON)) return NULL; /* @@ -5568,6 +5568,9 @@ static struct page *mc_handle_swap_pte(struct vm_area_struct *vma, return page; } + if (non_swap_entry(ent)) + return NULL; + /* * Because lookup_swap_cache() updates some statistics counter, * we call find_get_page() with swapper_space directly.