Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp222875pxx; Wed, 28 Oct 2020 03:17:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3G932A118Srj4q7P8YHQSKkUo/WLL1ItqyKGDZMaxWYbYJBm7B1AoIRmKNZCJ0KefXeLy X-Received: by 2002:a17:906:11d5:: with SMTP id o21mr6969635eja.401.1603880246606; Wed, 28 Oct 2020 03:17:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603880246; cv=none; d=google.com; s=arc-20160816; b=CWBkbMABfm+u9OrI793MxOtmHo61mZZFzAZdIa1cgDDGeg/VDVixEXRjT8HRQynUzK uAWZIv9I7NlQxlhbXADRwyu5rp2kjcHKsYulbfsV0Jy7kEhyzZLtso7kvuR7wq+Vzi1E nK9vYe8E+F55wv984SLdoFynKiURVWDfD1Pc6YTND/xBIhGmK/iimWnFP/ljC84I0aHF jn11ZK5Tj/uzkDsYzK06kYtGL3+wQlQKdKU5ynkQFntF6p+b0WfNjsQZPAyVVRKbGT8W w4XadXivFwmXyzhk+4eJfbVA+uqliQ1LArUFNyCV1/lilVcEDakldDleB+3jZalLpU+n tMoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nIvqeUrMgH23v8fi6lpRg5Kb21z5bqqj2oHK2KblZ5c=; b=OySEmANfodvNhBISx3ln9EM/9kYWR3x4igvZkzvJiJwIQqhS9Jqe4b3BQU+k5c15Od 0iVpOtUfG59vaOifY1LzUn2vFhKWZS7LAZrp9OjIfwgJE7IeFCuXYzDtnBLxNYQ0Wgrj O5NoE/GymV++tDzmRfUfaH+ne9p5HK+TG/Ff2zAzjz7HTTTXEnQ9X5NHuAvCSrVyGTMq 0AQVJ0llelMuVhFsY/kR1uiOOsJrrNUHk9WmaX/+R0WIxgNeC+gla0p4JgFe87QNi1JA ixIjP5FIoZ+/Hhrm16TYMj7VIxPj2RuiqlD9yd/H1WVNgNpU/R60LmUJJZN1x6Vzht94 Qnsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KjaEs4aD; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t1si2868715ejb.712.2020.10.28.03.17.04; Wed, 28 Oct 2020 03:17:26 -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=@kernel.org header.s=default header.b=KjaEs4aD; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760945AbgJ0OhI (ORCPT + 99 others); Tue, 27 Oct 2020 10:37:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:36014 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760930AbgJ0OhG (ORCPT ); Tue, 27 Oct 2020 10:37:06 -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 03D4522265; Tue, 27 Oct 2020 14:37:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603809425; bh=EZzu66es/pTQEHuhCK9SUv5b0SRQUZ6IXXn4dca0ef4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KjaEs4aDFOH1rpUfeyI3/TXy26en1LbTWyk0gbKBP8Kqh0ynSeS4BlWMI1afi5sbS 1SGwT3xEwQBAjFPL6lZ0cwZB20r4h9G53dGtXYarhEooR6RFKGagnH3vnYxklDi8Le kmHpwCFiCh/veaZNgV4J+NKqQzoUdEtHU33vSBsM= 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.4 192/408] mm/memcg: fix device private memcg accounting Date: Tue, 27 Oct 2020 14:52:10 +0100 Message-Id: <20201027135503.992728913@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135455.027547757@linuxfoundation.org> References: <20201027135455.027547757@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 ca1632850fb76..edf98f8588eeb 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5398,7 +5398,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; /* @@ -5417,6 +5417,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. -- 2.25.1