Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp3278188lfo; Mon, 23 May 2022 00:32:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw1KGSLUeYp+JAvDz8bRXGJ+5qDNI4Au8gJZgwMnjCSdeaRvoh7XvvK1pxnAilQKsD07O/K X-Received: by 2002:a65:6e88:0:b0:382:3851:50c8 with SMTP id bm8-20020a656e88000000b00382385150c8mr19415488pgb.270.1653291124610; Mon, 23 May 2022 00:32:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653291124; cv=none; d=google.com; s=arc-20160816; b=QxHmsRHb256Yu8DHSeQ5s8UaH7bdT7BVyOlbO0Q15+2QEEsUrfFyT5GOkxhTmcmvLv 5TCus/7woipxRH4OO8+iNIRjyL2emvIIBowoikHAIwkpgIfnzI8yFDGw4BKztKcG4dAz /5oTxQs4/KRSey9E0GOgrABjovzAmmbHEUbHaRqFQOwYU9QxUmx9q0kP+gAcGKwRZmLZ Uvd8eVsagNiS61WvBAWrDpv2DAiFTX0eQzv81irRgsR7TFB6CF13EZmHFZnUwUqJA8xF 4ugMslPfwuSCF0UzKBgPJv7wh/Nbl/0LU3WMqYDw//1gnRtjjmi3rUPA28CSYCv94N6B WLoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:subject :organization:from:references:cc:to:content-language:user-agent :mime-version:date:message-id:dkim-signature; bh=MiSSwi9xuJZ/cdu5ca2FrAQepB/n8ZjvRH3BZI2eDME=; b=eBRouACkmSA1Kh9SwRMjNE6b1+QDIYHol9TZc9j9GrAtsqevE8PmGvK53sV8is9m25 IU8RrXlyN43KSOhmlC5nd1GVVrOgQaA9wepHOZ4YsR5ikRge2xCDGwao0Bt2UYTfw6UQ Tdow3Ay4ZYUUyDdjGC/T1ESQ6S1ZsKwIE3Y5x3bgS5Sfadc7JRRckO6fUaOs+YM2GD+L olEoVIsYsfIbehBn867pwwKeWLGl/izZ3s9qPUertK7kQsv4vbKsiCrhobzxMwf8G0to 8wXTEoscdeKKSVk9s6i9BvzNYpra7B9WFL3ZquhAZCngcBAhTQmNU1rlMlvHUSClF7xL QECg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CgM5bmVS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id t20-20020a170902e1d400b0015ea8a12fddsi8044886pla.226.2022.05.23.00.32.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 00:32:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CgM5bmVS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D87FD13B8E0; Sun, 22 May 2022 23:43:37 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348120AbiEUPwI (ORCPT + 99 others); Sat, 21 May 2022 11:52:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245137AbiEUPwH (ORCPT ); Sat, 21 May 2022 11:52:07 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id ED57427B16 for ; Sat, 21 May 2022 08:52:05 -0700 (PDT) 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-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-212-48mQRWDLPkSIb8RURku9Wg-1; Sat, 21 May 2022 11:52:03 -0400 X-MC-Unique: 48mQRWDLPkSIb8RURku9Wg-1 Received: by mail-ed1-f72.google.com with SMTP id s9-20020aa7d789000000b0042ab9d77febso7563158edq.16 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=QE4wg+DK8gPqUmEkgaGcebrKZKI9YNG48jkMVWSAilmqrbUNWw39SkJjiq3jKFVomb jT+BnYpUQhQkQJ84wWX2FFw6RDUul/HLDB66coSHB0qNK9me9l7uHS3xAQdU16BTxURn txLhA0V1WJ9QMjXqHyGmo9bzxQqwkS1CubQW72td5Kg20cYAc0RlH/54ZGHddlnmORu4 GhkICdK57uxqAmLAJqTMri+vL/GEaWblrF5JQr1kSZHU+4PM4R42U4KoyjUtQ6HqtzN8 d/NpVqCObw2s4w4Ez8ktQzrc2yiLsqXS3C6VLW/zlr2l5YvVzwYI8cdFdN3ANa8w6XCW rClA== X-Gm-Message-State: AOAM532XX4iNK9Vo/uTgVzKMFpbTjMzdpVWBkRUgAOjcARLKcBxnh9fe F3vXufA0gnvUwg0W/yWQyQ4s5rIELrciB3gXxEAVA90uS02ynxCxQgoyKK3DEP2THvwMdKSyTVX yCZMsGIpehE5p3xSlypM5bK3/ X-Received: by 2002:aa7:d38f:0:b0:42a:a2e6:90d9 with SMTP id x15-20020aa7d38f000000b0042aa2e690d9mr16029555edq.305.1653148321980; Sat, 21 May 2022 08:52:01 -0700 (PDT) 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 Content-Language: en-US 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: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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