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 X-Spam-Level: X-Spam-Status: No, score=-8.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham 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 B9449C432BE for ; Tue, 17 Aug 2021 06:15:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4431460F41 for ; Tue, 17 Aug 2021 06:15:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4431460F41 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 983BF6B006C; Tue, 17 Aug 2021 02:15:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 933CE6B0072; Tue, 17 Aug 2021 02:15:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 822D56B0073; Tue, 17 Aug 2021 02:15:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0005.hostedemail.com [216.40.44.5]) by kanga.kvack.org (Postfix) with ESMTP id 665596B006C for ; Tue, 17 Aug 2021 02:15:02 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 0B0B01F209 for ; Tue, 17 Aug 2021 06:15:02 +0000 (UTC) X-FDA: 78483559644.27.0BD2747 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf14.hostedemail.com (Postfix) with ESMTP id 85F7260179A4 for ; Tue, 17 Aug 2021 06:15:01 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 29BBA60E78; Tue, 17 Aug 2021 06:15:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1629180900; bh=NZjiKqRb5lmmInzfCqVEdFiurrR2yJY2P60ADXWH3c4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=1VTUu8ohNsUCmIpWF5K2BJtCu68kxWHlhvISHVRM30dbPZNjODkm6eFbLOIQOUtgi caMChXiEbra7k1YJ4ITdQbZcpI7lORH13SSs44DO0+1zcAidDAkvhPgCiQ3kThguvk 27AkrHAoV7KRod8taHWWYIvhqKSHt7o2pH2HXksY= Date: Tue, 17 Aug 2021 08:14:58 +0200 From: Greg Kroah-Hartman To: Chen Huang Cc: Roman Gushchin , Muchun Song , Wang Hai , linux-kernel@vger.kernel.org, linux-mm@kvack.org, stable@vger.kernel.org, Andrew Morton , Alexei Starovoitov Subject: Re: [PATCH 5.10.y 01/11] mm: memcontrol: Use helpers to read page's memcg data Message-ID: References: <20210816072147.3481782-1-chenhuang5@huawei.com> <20210816072147.3481782-2-chenhuang5@huawei.com> <0d3c6aa4-be05-3c93-bdcd-ac30788d82bd@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <0d3c6aa4-be05-3c93-bdcd-ac30788d82bd@huawei.com> Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=korg header.b=1VTUu8oh; dmarc=pass (policy=none) header.from=linuxfoundation.org; spf=pass (imf14.hostedemail.com: domain of gregkh@linuxfoundation.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=gregkh@linuxfoundation.org X-Stat-Signature: 9irpp846rgbzagaycnnwraa6m5dzym41 X-Rspamd-Queue-Id: 85F7260179A4 X-Rspamd-Server: rspam05 X-HE-Tag: 1629180901-485494 Content-Transfer-Encoding: quoted-printable 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: On Tue, Aug 17, 2021 at 09:45:00AM +0800, Chen Huang wrote: >=20 >=20 > =E5=9C=A8 2021/8/16 21:35, Greg Kroah-Hartman =E5=86=99=E9=81=93: > > On Mon, Aug 16, 2021 at 09:21:11PM +0800, Chen Huang wrote: > >> > >> > >> =E5=9C=A8 2021/8/16 16:34, Greg Kroah-Hartman =E5=86=99=E9=81=93: > >>> On Mon, Aug 16, 2021 at 07:21:37AM +0000, Chen Huang wrote: > >>>> From: Roman Gushchin > >>> > >>> What is the git commit id of this patch in Linus's tree? > >>> > >>>> > >>>> Patch series "mm: allow mapping accounted kernel pages to userspac= e", v6. > >>>> > >>>> Currently a non-slab kernel page which has been charged to a memor= y cgroup > >>>> can't be mapped to userspace. The underlying reason is simple: Pa= geKmemcg > >>>> flag is defined as a page type (like buddy, offline, etc), so it t= akes a > >>>> bit from a page->mapped counter. Pages with a type set can't be m= apped to > >>>> userspace. > >>>> > >>>> But in general the kmemcg flag has nothing to do with mapping to > >>>> userspace. It only means that the page has been accounted by the = page > >>>> allocator, so it has to be properly uncharged on release. > >>>> > >>>> Some bpf maps are mapping the vmalloc-based memory to userspace, a= nd their > >>>> memory can't be accounted because of this implementation detail. > >>>> > >>>> This patchset removes this limitation by moving the PageKmemcg fla= g into > >>>> one of the free bits of the page->mem_cgroup pointer. Also it for= malizes > >>>> accesses to the page->mem_cgroup and page->obj_cgroups using new h= elpers, > >>>> adds several checks and removes a couple of obsolete functions. A= s the > >>>> result the code became more robust with fewer open-coded bit trick= s. > >>>> > >>>> This patch (of 4): > >>>> > >>>> Currently there are many open-coded reads of the page->mem_cgroup = pointer, > >>>> as well as a couple of read helpers, which are barely used. > >>>> > >>>> It creates an obstacle on a way to reuse some bits of the pointer = for > >>>> storing additional bits of information. In fact, we already do th= is for > >>>> slab pages, where the last bit indicates that a pointer has an att= ached > >>>> vector of objcg pointers instead of a regular memcg pointer. > >>>> > >>>> This commits uses 2 existing helpers and introduces a new helper t= o > >>>> converts all read sides to calls of these helpers: > >>>> struct mem_cgroup *page_memcg(struct page *page); > >>>> struct mem_cgroup *page_memcg_rcu(struct page *page); > >>>> struct mem_cgroup *page_memcg_check(struct page *page); > >>>> > >>>> page_memcg_check() is intended to be used in cases when the page c= an be a > >>>> slab page and have a memcg pointer pointing at objcg vector. It d= oes > >>>> check the lowest bit, and if set, returns NULL. page_memcg() cont= ains a > >>>> VM_BUG_ON_PAGE() check for the page not being a slab page. > >>>> > >>>> To make sure nobody uses a direct access, struct page's > >>>> mem_cgroup/obj_cgroups is converted to unsigned long memcg_data. > >>>> > >>>> Signed-off-by: Roman Gushchin > >>>> Signed-off-by: Andrew Morton > >>>> Signed-off-by: Alexei Starovoitov > >>>> Reviewed-by: Shakeel Butt > >>>> Acked-by: Johannes Weiner > >>>> Acked-by: Michal Hocko > >>>> Link: https://lkml.kernel.org/r/20201027001657.3398190-1-guro@fb.c= om > >>>> Link: https://lkml.kernel.org/r/20201027001657.3398190-2-guro@fb.c= om > >>>> Link: https://lore.kernel.org/bpf/20201201215900.3569844-2-guro@fb= .com > >>>> > >>>> Conflicts: > >>>> mm/memcontrol.c > >>> > >>> The "Conflicts:" lines should be removed. > >>> > >>> Please fix up the patch series and resubmit. But note, this seems > >>> really intrusive, are you sure these are all needed? > >>> > >> > >> OK=EF=BC=8CI will resend the patchset. > >> Roman Gushchin's patchset formalize accesses to the page->mem_cgroup= and > >> page->obj_cgroups. But for LRU pages and most other raw memcg, they = may > >> pin to a memcg cgroup pointer, which should always point to an objec= t cgroup > >> pointer. That's the problem I met. And Muchun Song's patchset fix th= is. > >> So I think these are all needed. > >=20 > > What in-tree driver causes this to happen and under what workload? > >=20 > >>> What UIO driver are you using that is showing problems like this? > >>> > >> > >> The UIO driver is my own driver, and it's creation likes this: > >> First, we register a device > >> pdev =3D platform_device_register_simple("uio_driver,0, NULL, 0); > >> and use uio_info to describe the UIO driver, the page is alloced and= used > >> for uio_vma_fault > >> info->mem[0].addr =3D (phys_addr_t) kzalloc(PAGE_SIZE, GFP_ATOMIC); > >=20 > > That is not a physical address, and is not what the uio api is for at > > all. Please do not abuse it that way. > >=20 > >> then we register the UIO driver. > >> uio_register_device(&pdev->dev, info) > >=20 > > So no in-tree drivers are having problems with the existing code, onl= y > > fake ones? >=20 > Yes, but the nullptr porblem may not just about uio driver. For now, pa= ge struct > has a union > union { > struct mem_cgroup *mem_cgroup; > struct obj_cgroup **obj_cgroups; > }; > For the slab pages, the union info should belong to obj_cgroups. And fo= r user > pages, it should belong to mem_cgroup. When a slab page changes its obj= _cgroups, > then another user page which is in the same compound page of that slab = page will > gets the wrong mem_cgroup in __mod_lruvec_page_state(), and will trigge= r nullptr > in mem_cgroup_lruvec(). Correct me if I'm wrong. Thanks! And how can that be triggered by a user in the 5.10.y kernel tree at the moment? I'm all for fixing problems, but this one does not seem like it is an actual issue for the 5.10 tree right now. Am I missing something? thanks, greg k-h