Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp337954pxb; Mon, 16 Aug 2021 06:38:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYQxLP7WoGelDFkHZFAbDS+wnVseF7J21y/vbTJJIgG3q3MzA39B67vKLFS/Dw0+BBB0Ak X-Received: by 2002:a50:ff03:: with SMTP id a3mr20130421edu.100.1629121089028; Mon, 16 Aug 2021 06:38:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629121089; cv=none; d=google.com; s=arc-20160816; b=A0WxvmLT2cU6IXClaQXFLm2MldcTe7yNFQwCAHOsmI9MdeEEc1t4ZQjJQzI1N0YW9/ jjZGuJ8vqjzAMen38C7AzM9t7iktfgfERSPt6S7nIWq7E+M5qOt8zt9/OKYgDY++i1Rl 3RptkE4ZcIee7/mfIIaJtrS8CHmm9aBN78DeeTsO99SJCa582Vdm077+eXzeIyd9Hp4X ZShWXnrUuJCeWgUceX7PUMZYTRh+DvSdFMBqvXlE3dGGfg52txAvlIwGC/VCx3dc8Nhh iANL6B+6flMtFv9aGk9AUrqTUnDP1w2KuIz3CYvgbdK1kAolXRKOJkbo15etyQpSOG3C cdxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=mRR+tnkNchAujy//rVb/elYHtE69zcoZwvDxpwvl5Qo=; b=h8kOGcGfcS956bwQJ+e+CRZh9c4AQXygtcBPK+ZeoxMN92W2XIowMAGZMBstu7qpUG XZVthM9zrTukMfLSsbBrQdxT/zfMZ0VXbaSJhCkqoy/rWQ61GL5atw7U8XjEAnD5t1YQ y3FQhyxHiHcthmZlEwRpUm/eY4rQqli1cOb5pmwfcVz8nttZSS2OuCfTK+syJKgVN0Ke seAsFOWqaqHvzo02qvfYxg+I+y0WCAR2Ko8OimwXmOmcfnw9Fvj6KFqJu0WMKGnc0y4t rJAyx6/uYEHrMAtucr1XG32ChRr3d1A5QlrxeitoGiYWv7gB3czU5rv4eEabFzgR7urV jw4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fGJUSESw; 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=pass (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 gf2si11807768ejb.500.2021.08.16.06.37.45; Mon, 16 Aug 2021 06:38:09 -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=@linuxfoundation.org header.s=korg header.b=fGJUSESw; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231368AbhHPNgw (ORCPT + 99 others); Mon, 16 Aug 2021 09:36:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:56754 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239681AbhHPNf4 (ORCPT ); Mon, 16 Aug 2021 09:35:56 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9F70D60E90; Mon, 16 Aug 2021 13:35:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1629120925; bh=V2djZ0s5eeYtPknbm6mCjf0Kvlgls1rw9uu907bgUCs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=fGJUSESwqddkOhbxJBKFSBoQkKCT63dyH7dKHeiKg2jInhttWHaz787y2iKM/ZITx eyfEHk59i49OYPoU5+TuSPZlQBYcZXK/HlzRjhQuWECbXIOHEhqZ/DGtVpdSU75GQy PrfpV+r9wqXD1kG6v0Dz90X4heFDYvKfjrM6JVnQ= Date: Mon, 16 Aug 2021 15:35:22 +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> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 16, 2021 at 09:21:11PM +0800, Chen Huang wrote: > > > 在 2021/8/16 16:34, Greg Kroah-Hartman 写道: > > 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 userspace", v6. > >> > >> Currently a non-slab kernel page which has been charged to a memory cgroup > >> can't be mapped to userspace. The underlying reason is simple: PageKmemcg > >> flag is defined as a page type (like buddy, offline, etc), so it takes a > >> bit from a page->mapped counter. Pages with a type set can't be mapped 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, and their > >> memory can't be accounted because of this implementation detail. > >> > >> This patchset removes this limitation by moving the PageKmemcg flag into > >> one of the free bits of the page->mem_cgroup pointer. Also it formalizes > >> accesses to the page->mem_cgroup and page->obj_cgroups using new helpers, > >> adds several checks and removes a couple of obsolete functions. As the > >> result the code became more robust with fewer open-coded bit tricks. > >> > >> 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 this for > >> slab pages, where the last bit indicates that a pointer has an attached > >> vector of objcg pointers instead of a regular memcg pointer. > >> > >> This commits uses 2 existing helpers and introduces a new helper to > >> 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 can be a > >> slab page and have a memcg pointer pointing at objcg vector. It does > >> check the lowest bit, and if set, returns NULL. page_memcg() contains 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.com > >> Link: https://lkml.kernel.org/r/20201027001657.3398190-2-guro@fb.com > >> 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,I 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 object cgroup > pointer. That's the problem I met. And Muchun Song's patchset fix this. > So I think these are all needed. What in-tree driver causes this to happen and under what workload? > > 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 = 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 = (phys_addr_t) kzalloc(PAGE_SIZE, GFP_ATOMIC); That is not a physical address, and is not what the uio api is for at all. Please do not abuse it that way. > then we register the UIO driver. > uio_register_device(&pdev->dev, info) So no in-tree drivers are having problems with the existing code, only fake ones? thanks, greg k-h