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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1660AC433F5 for ; Sat, 21 May 2022 15:52:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1A8046B0072; Sat, 21 May 2022 11:52:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1584D6B0073; Sat, 21 May 2022 11:52:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F39B56B0074; Sat, 21 May 2022 11:52:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E252B6B0072 for ; Sat, 21 May 2022 11:52:05 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id BA275208C7 for ; Sat, 21 May 2022 15:52:05 +0000 (UTC) X-FDA: 79490191410.25.A7B3E8E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf06.hostedemail.com (Postfix) with ESMTP id E5A3318001F for ; Sat, 21 May 2022 15:52:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653148324; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MiSSwi9xuJZ/cdu5ca2FrAQepB/n8ZjvRH3BZI2eDME=; b=CgM5bmVSD8DBTqWRjDia3+wjOFnya8LHS05DuKpnx9tHqN9AYcdqmGtE1A/a43Vxq8Ze+s mv+gq0ceXxttYRL6IevqoAESblU9sDFJWWYkKNkAJKPbrYY1sljQ3urX5bg3Xr3ljCPXcQ AfADoKrP+rwGcLCcrPGbDk821NaevvE= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-610-KtX9MR4CPW6rJyQ6yNuCcQ-1; Sat, 21 May 2022 11:52:03 -0400 X-MC-Unique: KtX9MR4CPW6rJyQ6yNuCcQ-1 Received: by mail-ed1-f69.google.com with SMTP id s9-20020aa7c549000000b0042ab6ab62f0so7537995edr.14 for ; Sat, 21 May 2022 08:52:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:to:cc:references:from:organization:subject :in-reply-to:content-transfer-encoding; bh=MiSSwi9xuJZ/cdu5ca2FrAQepB/n8ZjvRH3BZI2eDME=; b=3wrP2aSRWoT/MU2JvQzBDt7xrq4ruHX5zTjGzPLUQqHOr1VfTNmZwMjwdLjkBD2mjv 2a0SDJD1eScOvGJ1o/ncdlmmvlbWk3Otj0ogxpev3krw6tNHgFhRei7hEvcJDmEYgYil hLeaLD9n3Zq5Hc4RQQa3r1YeZIII60IG/85CSqnaKcgJN83BBZ3A1QpqWfz00ayL2sqd LtTYPuCKKfoUsPc+j4O7huyybyEYU4MfmNE6j48ohf/lbDdQ8yfPF+y6mvVpHETnEh4P 79FS2VmvlVb7mvI8vQyPPnKLIJBT/caeZiolUn6ulJPAYn5JzaWZz9KQTKZWUrqae8Zo dHzw== X-Gm-Message-State: AOAM5338/X1vlfPMq7uE7Yr2mWKSYR1mH+IwQm4Ptx663rgOnRHLPXZ+ 9cm/651d87fExSiFFhMQXJtVNd8YRcfKPFQIA1ltR34/tnbk3irWMNitZ6/38n4OaSQFJZoJght X8mdFYfUmWAk= X-Received: by 2002:aa7:d38f:0:b0:42a:a2e6:90d9 with SMTP id x15-20020aa7d38f000000b0042aa2e690d9mr16029554edq.305.1653148321980; Sat, 21 May 2022 08:52:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4xkzaG+uCKjuzlqbWkg8yEWYTiB8UbHwNK2rqRkeJUZK5IAmfpUQKhgxr7TOVUyWMyhjOwQ== X-Received: by 2002:aa7:d38f:0:b0:42a:a2e6:90d9 with SMTP id x15-20020aa7d38f000000b0042aa2e690d9mr16029531edq.305.1653148321697; Sat, 21 May 2022 08:52:01 -0700 (PDT) Received: from [172.29.4.249] ([45.90.93.190]) by smtp.gmail.com with ESMTPSA id c62-20020a509fc4000000b0042aae3f282esm5714786edf.65.2022.05.21.08.51.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 21 May 2022 08:52:01 -0700 (PDT) Message-ID: Date: Sat, 21 May 2022 17:51:58 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 To: Minchan Kim , Mike Kravetz Cc: John Hubbard , Andrew Morton , syzbot , linux-kernel@vger.kernel.org, linux-mm@kvack.org, llvm@lists.linux.dev, nathan@kernel.org, ndesaulniers@google.com, syzkaller-bugs@googlegroups.com, trix@redhat.com, Matthew Wilcox , Stephen Rothwell References: <4809b134-a37a-50b8-4c25-44548bc1048f@nvidia.com> <6d281052-485c-5e17-4f1c-ef5689831450@oracle.com> <0be9132d-a928-9ebe-a9cf-6d140b907d59@nvidia.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [syzbot] WARNING in follow_hugetlb_page In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: E5A3318001F X-Stat-Signature: x5erakk8x5dejw6ukyqd9b8k6qaugo3e Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=CgM5bmVS; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf06.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=david@redhat.com X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1653148321-276896 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 21.05.22 17:24, Minchan Kim wrote: > On Fri, May 20, 2022 at 05:04:22PM -0700, Mike Kravetz wrote: >> On 5/20/22 16:43, Minchan Kim wrote: >>> On Fri, May 20, 2022 at 04:31:31PM -0700, Mike Kravetz wrote: >>>> On 5/20/22 15:56, John Hubbard wrote: >>>>> On 5/20/22 15:19, Minchan Kim wrote: >>>>>> The memory offline would be an issue so we shouldn't allow pinning of any >>>>>> pages in *movable zone*. >>>>>> >>>>>> Isn't alloc_contig_range just best effort? Then, it wouldn't be a big >>>>>> problem to allow pinning on those area. The matter is what target range >>>>>> on alloc_contig_range is backed by CMA or movable zone and usecases. >>>>>> >>>>>> IOW, movable zone should be never allowed. But CMA case, if pages >>>>>> are used by normal process memory instead of hugeTLB, we shouldn't >>>>>> allow longterm pinning since someone can claim those memory suddenly. >>>>>> However, we are fine to allow longterm pinning if the CMA memory >>>>>> already claimed and mapped at userspace(hugeTLB case IIUC). >>>>>> >>>>> >>>>> From Mike's comments and yours, plus a rather quick reading of some >>>>> CMA-related code in mm/hugetlb.c (free_gigantic_page(), alloc_gigantic_pages()), the following seems true: >>>>> >>>>> a) hugetlbfs can allocate pages *from* CMA, via cma_alloc() >>>>> >>>>> b) while hugetlbfs is using those CMA-allocated pages, it is debatable >>>>> whether those pages should be allowed to be long term pinned. That's >>>>> because there are two cases: >>>>> >>>>>     Case 1: pages are longterm pinned, then released, all while >>>>>             owned by hugetlbfs. No problem. >>>>> >>>>>     Case 2: pages are longterm pinned, but then hugetlbfs releases the >>>>>             pages entirely (via unmounting hugetlbfs, I presume). In >>>>>             this case, we now have CMA page that are long-term pinned, >>>>>             and that's the state we want to avoid. >>>> >>>> I do not think case 2 can happen. A hugetlb page can only be changed back >>>> to 'normal' (buddy) pages when ref count goes to zero. >>>> >>>> It should also be noted that hugetlb code sets up the CMA area from which >>>> hugetlb pages can be allocated. This area is never unreserved/freed. >>>> >>>> I do not think there is a reason to disallow long term pinning of hugetlb >>>> pages allocated from THE hugetlb CMA area. Hm. We primarily use CMA for gigantic pages only IIRC. Ordinary huge pages come via the buddy. Assume we allocated a (movable) 2MiB huge page ordinarily via the buddy and it ended up on that CMA area by pure luck (as it's movable). If we'd allow to pin it long-term, allocating a gigantic page from the designated CMA area would fail. So we'd want to allow long-term pinning a gigantic page but we'd not want to allow long-term pinning an ordinary huge page. We'd want to migrate the latter away. The general rules are: ZONE_MOVABLE: nobody is allowed to place unmovable allocations there; it could prevent memory offlining/unplug. CMA: nobody *but the designated owner* is allowed to place unmovable memory there; it could prevent the actual owner to allocate contiguous memory. As explained above, it gets a bit weird if the owner (hugetlb) deals with different allocation types (huge vs. gigantic pages). >> Unless I do not understand, normal movable memory allocations can fall >> back to CMA areas? Yes, just like ZONE_MOVABLE IIRC. > > In the case, Yes, it would be fallback if gfp_flag was __GFP_MOVABLE. > > If HugeTLB support it(I think so), pin_user_pages with FOLL_LONGTERM > will migrate the page out of movable/CMA before the longterm pinning > so IMHO, we shouldn't have the problem. As explained, the tricky bit would be hitting a gigantic page that's valid to reside permanently on the designated CMA area. IIRC, some gigantic pages are indeed movable, but we never place them on ZONE_MOVABLE because migration is unlikely to work in practice. -- Thanks, David / dhildenb