From patchwork Tue Oct 27 13:50:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 312237 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6BF10C6369E for ; Tue, 27 Oct 2020 16:46:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3414222263 for ; Tue, 27 Oct 2020 16:46:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603817195; bh=uberBHcy7z7m1yYkUC/Co7fj/8pH244+rfuv9cAFQkQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=tNmjd1J0m7S1XjS09Wv8AN1IjSfZ3NjJkKAB+zh7KZIaa14KsoptJ4z5AjbtH7tqL /EzG0tjcPVDOJeoJhAJk12PBN7aR6alnuURYwm/BFF5IMq2f49o6srYE/5Tt1f+gW9 dFVEyhU0ZLkI/+CXgqD8uYlGvNWbPtClG5JW8PWY= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S368856AbgJ0PmC (ORCPT ); Tue, 27 Oct 2020 11:42:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:54746 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1800522AbgJ0PgD (ORCPT ); Tue, 27 Oct 2020 11:36:03 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6B8C922275; Tue, 27 Oct 2020 15:36:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603812963; bh=uberBHcy7z7m1yYkUC/Co7fj/8pH244+rfuv9cAFQkQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E5xPixIr2l2jkyKFpKCElu7CNkVSD0OK5XlUiafXQjN2exzYK+QcmgJMfMs9i4QLP U5RbI66H8CAdIicyGGMaT0SmI/ulGXSTWhNfNanY+E1xDcP2s3fBmFXpxw8Ayex5iu WnTFigh+pvFsK1uGzrDSrUGEyenVPkr9LTmxkBk0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ralph Campbell , Andrew Morton , Johannes Weiner , Michal Hocko , Vladimir Davydov , Jerome Glisse , Balbir Singh , Ira Weiny , Linus Torvalds , Sasha Levin Subject: [PATCH 5.9 391/757] mm/memcg: fix device private memcg accounting Date: Tue, 27 Oct 2020 14:50:41 +0100 Message-Id: <20201027135508.894400225@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135450.497324313@linuxfoundation.org> References: <20201027135450.497324313@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Ralph Campbell [ Upstream commit 9a137153fc8798a89d8fce895cd0a06ea5b8e37c ] 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. I assume the memory cgroup accounting would be off somehow when moving a process to another memory cgroup. Currently, the device private page is charged like a normal anonymous page when allocated and is uncharged when the page is freed so I think that path is OK. Signed-off-by: Ralph Campbell Signed-off-by: Andrew Morton Acked-by: Johannes Weiner Cc: Michal Hocko Cc: Vladimir Davydov Cc: Jerome Glisse Cc: Balbir Singh Cc: Ira Weiny Link: https://lkml.kernel.org/r/20201009215952.2726-1-rcampbell@nvidia.com xFixes: c733a82874a7 ("mm/memcontrol: support MEMORY_DEVICE_PRIVATE") Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/memcontrol.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index b9688a4b1d550..9eefdb9cc2303 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5511,7 +5511,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; /* @@ -5530,6 +5530,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.