Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751618AbdIAHbs (ORCPT ); Fri, 1 Sep 2017 03:31:48 -0400 Received: from mx2.suse.de ([195.135.220.15]:41736 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751386AbdIAHbr (ORCPT ); Fri, 1 Sep 2017 03:31:47 -0400 Subject: Re: [PATCH 1/3] mm/cma: manage the memory of the CMA area by using the ZONE_MOVABLE To: Laura Abbott , Joonsoo Kim Cc: Andrew Morton , Rik van Riel , Johannes Weiner , mgorman@techsingularity.net, Minchan Kim , Marek Szyprowski , Michal Nazarewicz , "Aneesh Kumar K . V" , Russell King , Will Deacon , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@lge.com, Kees Cook References: <1503556593-10720-1-git-send-email-iamjoonsoo.kim@lge.com> <1503556593-10720-2-git-send-email-iamjoonsoo.kim@lge.com> <20170831014048.GA24271@js1304-P5Q-DELUXE> From: Vlastimil Babka Message-ID: <61029e90-2835-8195-3682-442d469fed39@suse.cz> Date: Fri, 1 Sep 2017 09:31:43 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2234 Lines: 52 On 08/31/2017 05:07 PM, Laura Abbott wrote: > On 08/31/2017 07:32 AM, Vlastimil Babka wrote: >> On 08/31/2017 03:40 AM, Joonsoo Kim wrote: >>> On Tue, Aug 29, 2017 at 11:16:18AM +0200, Vlastimil Babka wrote: >>>> >>>> BTW, if we dropped NR_FREE_CMA_PAGES, could we also drop MIGRATE_CMA and >>>> related hooks? Is that counter really that useful as it works right now? >>>> It will decrease both by CMA allocations (which has to be explicitly >>>> freed) and by movable allocations (which can be migrated). What if only >>>> CMA alloc/release touched it? >>> >>> I think that NR_FREE_CMA_PAGES would not be as useful as previous. We >>> can remove it. >>> >>> However, removing MIGRATE_CMA has a problem. There is an usecase to >>> check if the page comes from the CMA area or not. See >>> check_page_span() in mm/usercopy.c. I can implement it differently by >>> iterating whole CMA area and finding the match, but I'm not sure it's >>> performance effect. I guess that it would be marginal. >> >> +CC Kees Cook >> >> Hmm, seems like this check is to make sure we don't copy from/to parts >> of kernel memory we're not supposed to? Then I believe checking that >> pages are in ZONE_MOVABLE should then give the same guarantees as >> MIGRATE_CMA. >> > > The check is to make sure we are copying only to a single page unless > that page is allocated with __GFP_COMP. CMA needs extra checks since > its allocations have nothing to do with compound page. Checking > ZONE_MOVABLE might cause us to miss some cases of copying to vanilla > ZONE_MOVABLE pages. How big problem is that? ZONE_MOVABLE should not contain kernel pages, so from the kernel protection side we are OK? I expect there's another check somewhere that the pages are not userspace, as that would be unexpected on a wrong side of copy_to/from_user, no? Also you can already miss some cases with the is_migrate_cma check, because pages might be in the CMA pageblocks but not be allocated by CMA itself - movable pages allocation can fallback here. >> BTW the comment says "Reject if range is entirely either Reserved or >> CMA" but the code does the opposite thing. I assume the comment is wrong? >> > > Yes, I think that needs clarification. > > Thanks, > Laura >