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=-4.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no 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 DE865C433E0 for ; Fri, 24 Jul 2020 09:05:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 95D4C2068F for ; Fri, 24 Jul 2020 09:05:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bytedance-com.20150623.gappssmtp.com header.i=@bytedance-com.20150623.gappssmtp.com header.b="lKqxA8aG" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 95D4C2068F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 076076B0007; Fri, 24 Jul 2020 05:05:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F418B6B000A; Fri, 24 Jul 2020 05:05:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E08F36B000C; Fri, 24 Jul 2020 05:05:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0224.hostedemail.com [216.40.44.224]) by kanga.kvack.org (Postfix) with ESMTP id C5AE86B0007 for ; Fri, 24 Jul 2020 05:05:06 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 40821181A20BE for ; Fri, 24 Jul 2020 09:05:06 +0000 (UTC) X-FDA: 77072385012.22.sail53_511082026f46 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id 131FD18108308 for ; Fri, 24 Jul 2020 09:05:06 +0000 (UTC) X-HE-Tag: sail53_511082026f46 X-Filterd-Recvd-Size: 4742 Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by imf12.hostedemail.com (Postfix) with ESMTP for ; Fri, 24 Jul 2020 09:05:05 +0000 (UTC) Received: by mail-pl1-f195.google.com with SMTP id x8so4085641plm.10 for ; Fri, 24 Jul 2020 02:05:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=dJk0fXPunD7T/D5AVyjQEsNkNoXfI8ghmpNswYCIQ+s=; b=lKqxA8aGc7K9NzmQLYiWeEyRjpzKPH0blU5CHfbuSvK+02UDgogw+q1KXJNiqGDUQo rLR1hRiHnu5oFwv10CZ+GVGH2CGgOWkBXWYk//dbBzwHipMuwUA9qEy7y1Jn5gX6Z5K7 UJ76IFF+NPl3Kb0cAzY9U5DY0ux9kZes/ohz9ihITTAc0vKCwyPle6Imfk276PSx/YBN ZlRwCib5SWxswWCFeevh5L7A7JTnjnHP2ztQ7PV6oXDXjKkDhNP7obbz9gp747djk18k zQfzH34OefTBx80I36pc1eHwt8VwfPU4gIEa1xvvLDHbGrU+gfDQ9RJZ9Hd5ZrZiKGQ8 HNpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=dJk0fXPunD7T/D5AVyjQEsNkNoXfI8ghmpNswYCIQ+s=; b=SrHTbQagWk0vlVWlGFcn600VuNzl60jj4rdognEW92GYjxa7KNFqrQhM63iyTOJX+p GFI9pqPeL2kAXHiOM7HY1OEK9GxfNLCMyNNY69AnfK2IOIKnz4TQxOuywNnd2EIponae 6g0UA6G/TTuNWJi/B5sm3mIhMdEi00/LeM8C7Ibvxf7gJbVh3d/rZwjUM2j0YRlMa68i +9ZHXtCoi1kAs7Qiv0kRnxafgQgzrSbubOyh7gTCNMZYWbKBJFzZt69kbGKTToKnUEa+ Bb0nYvJVNzpj48+CurNY1dY7WhYYWKo9RI2e+JrCril5f3SpbYucQ0KO7fUp/+VzDtYc UDsw== X-Gm-Message-State: AOAM53080BDKS3fbp902l7pr5mmI8DBrAbmJVW3z3uUKfITYRtCTno6Z IFWa4N6r7aq4jS2rfcTsFig3Jij8fwL5NS2snbsoiA== X-Google-Smtp-Source: ABdhPJxeA0hqXJHpVHzj1cwmFS5tzvEzSY3DMRZ4Hx39L3nWeQW9bZb9LB+BrACsZn0Sb547epBrIqwxWO5voC6C5dU= X-Received: by 2002:a17:90a:20e9:: with SMTP id f96mr4513310pjg.13.1595581504357; Fri, 24 Jul 2020 02:05:04 -0700 (PDT) MIME-Version: 1.0 References: <20200723074417.89467-1-songmuchun@bytedance.com> <20200724073942.GE4061@dhcp22.suse.cz> In-Reply-To: <20200724073942.GE4061@dhcp22.suse.cz> From: Muchun Song Date: Fri, 24 Jul 2020 17:04:28 +0800 Message-ID: Subject: Re: [Phishing Risk] [External] Re: [PATCH] mm/hugetlb: add mempolicy check in the reservation routine To: Michal Hocko Cc: mike.kravetz@oracle.com, Andrew Morton , Linux Memory Management List , LKML , Jianchao Guo Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 131FD18108308 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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 Fri, Jul 24, 2020 at 3:39 PM Michal Hocko wrote: > > On Thu 23-07-20 15:44:17, Muchun Song wrote: > > In the reservation routine, we only check whether the cpuset meets > > the memory allocation requirements. But we ignore the mempolicy of > > MPOL_BIND case. If someone mmap hugetlb succeeds, but the subsequent > > memory allocation may fail due to mempolicy restrictions and receives > > the SIGBUS signal. This can be reproduced by the follow steps. > > > > 1) Compile the test case. > > cd tools/testing/selftests/vm/ > > gcc map_hugetlb.c -o map_hugetlb > > > > 2) Pre-allocate huge pages. Suppose there are 2 numa nodes in the > > system. Each node will pre-allocate one huge page. > > echo 2 > /proc/sys/vm/nr_hugepages > > > > 3) Run test case(mmap 4MB). We receive the SIGBUS signal. > > numactl --membind=0 ./map_hugetlb 4 > > Cpusets and mempolicy interaction has always been a nightmare and Yeah, I agree with you. > semantic might get really awkward in some cases. In this case I am not > really sure anybody really does soemthing like that but anyway... Someone may like to use numactl to bind memory nodes. So I think that it is better to add a mempolicy check. > > [...] > > > -static unsigned int cpuset_mems_nr(unsigned int *array) > > +static nodemask_t *mempolicy_current_bind_nodemask(void) > > +{ > > + struct mempolicy *mpol; > > + nodemask_t *nodemask; > > + > > + mpol = get_task_policy(current); > > + if (mpol->mode == MPOL_BIND) > > + nodemask = &mpol->v.nodes; > > + else > > + nodemask = NULL; > > + > > + return nodemask; > > +} > > We already have policy_nodemask which tries to do this. Is there any > reason to not reuse it? Yeah, we can reuse it, I didn't know it before. Thanks. > -- > Michal Hocko > SUSE Labs -- Yours, Muchun