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=-7.0 required=3.0 tests=INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,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 4C36AC433DF for ; Tue, 9 Jun 2020 13:54:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 16E2020737 for ; Tue, 9 Jun 2020 13:54:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 16E2020737 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id AB99B6B000D; Tue, 9 Jun 2020 09:54:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A90B86B000E; Tue, 9 Jun 2020 09:54:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 981306B0010; Tue, 9 Jun 2020 09:54:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0111.hostedemail.com [216.40.44.111]) by kanga.kvack.org (Postfix) with ESMTP id 7FC096B000D for ; Tue, 9 Jun 2020 09:54:34 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 3644E8400 for ; Tue, 9 Jun 2020 13:54:34 +0000 (UTC) X-FDA: 76909818468.20.crowd76_1c0f41c26dc3 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id 022A518009B5C for ; Tue, 9 Jun 2020 13:54:33 +0000 (UTC) X-HE-Tag: crowd76_1c0f41c26dc3 X-Filterd-Recvd-Size: 6219 Received: from mail-ed1-f68.google.com (mail-ed1-f68.google.com [209.85.208.68]) by imf21.hostedemail.com (Postfix) with ESMTP for ; Tue, 9 Jun 2020 13:54:33 +0000 (UTC) Received: by mail-ed1-f68.google.com with SMTP id l1so16414471ede.11 for ; Tue, 09 Jun 2020 06:54:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=u6d5a1wYS310TnY2RCLtD0HWF1rRF6Bt1vMfKfFcb28=; b=Of28nz76ZwI3Cl6dbae9mppvdGzjez435nuZ+VzaVETn5aJgJdMqnmIsXbHNwpv4df xl30lJxNUfD1KaFFJ3MZ62ojzXyqHPIMAx3qBHMfDm2lwfgnvkbz6eh2ky4TMAqzYEaj bz2INXUWA+kHB+NJO6RdTc1VbzL1wbvABoeBV5sOAWJ03CUwVMngdEt59YR9brUKLw1u 23pzE/7PpaZa74PFItlgOJA3cwzk2rMsQWWCkEqYTlgaA3Fjz1DyOPN60vv8nlZOnyjP YysWhmI4OPeBAVjdzfHfH9FYWTgghPE3OhXITnTaZHob+bUommwaoOUuzSxaRdp9mU99 U7Kg== X-Gm-Message-State: AOAM5331achJpPCcj5mN7IOa9Bk9DPPGMR4DzGZ+O+eBdV/fji53LPxX ayLhoKAHyHpOljmH5kDWBHI= X-Google-Smtp-Source: ABdhPJyDNXxQrUuqOAS5w0ko4VQewnI1d3vzHbe9r7WdhIfFeYSIRzf4jOqjl7yqnwQtmtBTOA8ULg== X-Received: by 2002:a05:6402:1767:: with SMTP id da7mr27430433edb.90.1591710872569; Tue, 09 Jun 2020 06:54:32 -0700 (PDT) Received: from localhost (ip-37-188-174-195.eurotel.cz. [37.188.174.195]) by smtp.gmail.com with ESMTPSA id dg24sm12595287edb.55.2020.06.09.06.54.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2020 06:54:31 -0700 (PDT) Date: Tue, 9 Jun 2020 15:54:31 +0200 From: Michal Hocko To: js1304@gmail.com Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@lge.com, Vlastimil Babka , Christoph Hellwig , Roman Gushchin , Mike Kravetz , Naoya Horiguchi , Joonsoo Kim Subject: Re: [PATCH v2 07/12] mm/hugetlb: do not modify user provided gfp_mask Message-ID: <20200609135431.GI22623@dhcp22.suse.cz> References: <1590561903-13186-1-git-send-email-iamjoonsoo.kim@lge.com> <1590561903-13186-8-git-send-email-iamjoonsoo.kim@lge.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1590561903-13186-8-git-send-email-iamjoonsoo.kim@lge.com> X-Rspamd-Queue-Id: 022A518009B5C X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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 Wed 27-05-20 15:44:58, Joonsoo Kim wrote: > From: Joonsoo Kim > > It's not good practice to modify user input. Instead of using it to > build correct gfp_mask for APIs, this patch introduces another gfp_mask > field, __gfp_mask, for internal usage. Ugh, this is really ugly. It is just hugetlb to add __GFP_THISNODE as a special case. This is an ugly hack but I do not think we want to work around it by yet another hack. Moreover it seems that the __GFP_THISNODE might be not needed anymore as pointed out in a reply to earlier patch. > Signed-off-by: Joonsoo Kim > --- > mm/hugetlb.c | 19 ++++++++++--------- > mm/internal.h | 2 ++ > 2 files changed, 12 insertions(+), 9 deletions(-) > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index e465582..4757e72 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -1068,15 +1068,15 @@ static struct page *dequeue_huge_page_nodemask(struct hstate *h, > struct zoneref *z; > int node = NUMA_NO_NODE; > > - zonelist = node_zonelist(ac->nid, ac->gfp_mask); > + zonelist = node_zonelist(ac->nid, ac->__gfp_mask); > > retry_cpuset: > cpuset_mems_cookie = read_mems_allowed_begin(); > for_each_zone_zonelist_nodemask(zone, z, zonelist, > - gfp_zone(ac->gfp_mask), ac->nmask) { > + gfp_zone(ac->__gfp_mask), ac->nmask) { > struct page *page; > > - if (!cpuset_zone_allowed(zone, ac->gfp_mask)) > + if (!cpuset_zone_allowed(zone, ac->__gfp_mask)) > continue; > /* > * no need to ask again on the same node. Pool is node rather than > @@ -1127,8 +1127,8 @@ static struct page *dequeue_huge_page_vma(struct hstate *h, > if (avoid_reserve && h->free_huge_pages - h->resv_huge_pages == 0) > goto err; > > - ac.gfp_mask = htlb_alloc_mask(h); > - ac.nid = huge_node(vma, address, ac.gfp_mask, &mpol, &ac.nmask); > + ac.__gfp_mask = htlb_alloc_mask(h); > + ac.nid = huge_node(vma, address, ac.__gfp_mask, &mpol, &ac.nmask); > > page = dequeue_huge_page_nodemask(h, &ac); > if (page && !avoid_reserve && vma_has_reserves(vma, chg)) { > @@ -1951,7 +1951,7 @@ static struct page *alloc_migrate_huge_page(struct hstate *h, > if (hstate_is_gigantic(h)) > return NULL; > > - page = alloc_fresh_huge_page(h, ac->gfp_mask, > + page = alloc_fresh_huge_page(h, ac->__gfp_mask, > ac->nid, ac->nmask, NULL); > if (!page) > return NULL; > @@ -1989,9 +1989,10 @@ struct page *alloc_buddy_huge_page_with_mpol(struct hstate *h, > struct page *alloc_huge_page_nodemask(struct hstate *h, > struct alloc_control *ac) > { > - ac->gfp_mask |= htlb_alloc_mask(h); > + ac->__gfp_mask = htlb_alloc_mask(h); > + ac->__gfp_mask |= ac->gfp_mask; > if (ac->nid == NUMA_NO_NODE) > - ac->gfp_mask &= ~__GFP_THISNODE; > + ac->__gfp_mask &= ~__GFP_THISNODE; > > spin_lock(&hugetlb_lock); > if (h->free_huge_pages - h->resv_huge_pages > 0) { > @@ -2010,7 +2011,7 @@ struct page *alloc_huge_page_nodemask(struct hstate *h, > * will not come from CMA area > */ > if (ac->skip_cma) > - ac->gfp_mask &= ~__GFP_MOVABLE; > + ac->__gfp_mask &= ~__GFP_MOVABLE; > > return alloc_migrate_huge_page(h, ac); > } > diff --git a/mm/internal.h b/mm/internal.h > index 159cfd6..2dc0268 100644 > --- a/mm/internal.h > +++ b/mm/internal.h > @@ -619,6 +619,8 @@ struct alloc_control { > nodemask_t *nmask; > gfp_t gfp_mask; > bool skip_cma; > + > + gfp_t __gfp_mask; /* Used internally in API implementation */ > }; > > #endif /* __MM_INTERNAL_H */ > -- > 2.7.4 -- Michal Hocko SUSE Labs