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=-13.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 74DCCC47080 for ; Tue, 1 Jun 2021 02:48:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EB5A761186 for ; Tue, 1 Jun 2021 02:48:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EB5A761186 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5F0AB6B006C; Mon, 31 May 2021 22:48:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5A1168D0002; Mon, 31 May 2021 22:48:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 441CC6B0070; Mon, 31 May 2021 22:48:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0095.hostedemail.com [216.40.44.95]) by kanga.kvack.org (Postfix) with ESMTP id 106CE6B006C for ; Mon, 31 May 2021 22:48:36 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 94306A8C5 for ; Tue, 1 Jun 2021 02:48:35 +0000 (UTC) X-FDA: 78203621790.04.029D852 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) by imf10.hostedemail.com (Postfix) with ESMTP id 1DC6E4202A14 for ; Tue, 1 Jun 2021 02:48:23 +0000 (UTC) Received: by mail-pj1-f51.google.com with SMTP id k22-20020a17090aef16b0290163512accedso800946pjz.0 for ; Mon, 31 May 2021 19:48:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=WT/3Z5F3+KrogdCPcDO5jmg/aiO0PKvvWArp+0Dl7N4=; b=SFhgKy5W5TkuYv2+si6888+ZtbwNwbmPPZ8paqH7ycTbB7RxZ/rRNutGRLUw7fc9r5 4sT8144fcmFlWPSV64oboX9A70pSf069BMyEUiu7BgOJFKLjdfdCx3ttIiyNDlr+F1ME 7PU5k+0VRWhYEZvA7PBkUp5zS6eAip44AkS4oREo5notp2AUQYN5A3ODt0e4aSbKSQax nw2b1NKAkVGsLfdinWCmAYnMM9hD16XL2J7lV+lIJH9ezf6sH/DysrEzLe41VdCfGfdg aHd+tGWaxt+qzv89rGGnv7sg4yBvxUwfoRNJqOeaxr/z+tNtUBbpiNKgL/0S6tsnd/Jx 21Gw== 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=WT/3Z5F3+KrogdCPcDO5jmg/aiO0PKvvWArp+0Dl7N4=; b=pHbnatITiLE9FLYcbGAN4J2hK/OpI4nLP0zyCT2FSxG5jbN4gNW/ai+z00h5hf7A+x ZQ3dfCtxkaNyDTDxGJlPYbc/YTaYochM76KE4I4NSJzMyK7ihpVVcR1Xh5qVpCZ1OIrA EVUOCfthFW8P/r0IwGGh1Fw3qETvATnLy5xcF+bP1CA+kX9ngtLm52BiusXlOK+BkvWm MrPGra0uggZa/+Ju04tymmlbRDamIfmcsmLY3FMIHrk7Rd4mfu0JrAfZFVPFRRNeYE31 X8RV/qFugknWkCqNgTn6feKaMFVOFHRpY+4DApwMw4hNDcZHJMfLuQZcvvaorarBeNLA bSxw== X-Gm-Message-State: AOAM532enymm8JDD693rpKbevH02b54o0M3XUcG65DvF7jFJThY1mrgm UmwUt33I6Hhrx5TnrvMmYZId2TIr7EeVaR1clYFjRw== X-Google-Smtp-Source: ABdhPJxEndm4+xqEXGKQHxATyTSaARptJBXAqNT1OqBoTnag1T1pYksdYDrweSEVFbdMxuEDBo7KpnUghUoHOcUfQ84= X-Received: by 2002:a17:90b:4b0f:: with SMTP id lx15mr21579613pjb.184.1622515714118; Mon, 31 May 2021 19:48:34 -0700 (PDT) MIME-Version: 1.0 References: <20210528005029.88088-1-almasrymina@google.com> <20210531162527.caeae9545ea2843c5f62bc9c@linux-foundation.org> <20210531173652.c21404a16a8f8542ce40afa8@linux-foundation.org> In-Reply-To: <20210531173652.c21404a16a8f8542ce40afa8@linux-foundation.org> From: Mina Almasry Date: Mon, 31 May 2021 19:48:23 -0700 Message-ID: Subject: Re: [PATCH v4] mm, hugetlb: fix racy resv_huge_pages underflow on UFFDIO_COPY To: Andrew Morton Cc: Axel Rasmussen , Peter Xu , Linux-MM , Mike Kravetz , open list Content-Type: text/plain; charset="UTF-8" Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20161025 header.b=SFhgKy5W; spf=pass (imf10.hostedemail.com: domain of almasrymina@google.com designates 209.85.216.51 as permitted sender) smtp.mailfrom=almasrymina@google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 1DC6E4202A14 X-Stat-Signature: iijjgrizyijsk3nyhic7bw7gfamty89d X-HE-Tag: 1622515703-244324 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000011, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, May 31, 2021 at 5:36 PM Andrew Morton wrote: > > On Mon, 31 May 2021 17:11:52 -0700 Mina Almasry wrote: > > > On Mon, May 31, 2021 at 4:25 PM Andrew Morton wrote: > > > > > > On Thu, 27 May 2021 17:50:29 -0700 Mina Almasry wrote: > > > > > > > On UFFDIO_COPY, if we fail to copy the page contents while holding the > > > > hugetlb_fault_mutex, we will drop the mutex and return to the caller > > > > after allocating a page that consumed a reservation. In this case there > > > > may be a fault that double consumes the reservation. To handle this, we > > > > free the allocated page, fix the reservations, and allocate a temporary > > > > hugetlb page and return that to the caller. When the caller does the > > > > copy outside of the lock, we again check the cache, and allocate a page > > > > consuming the reservation, and copy over the contents. > > > > > > > > Test: > > > > Hacked the code locally such that resv_huge_pages underflows produce > > > > a warning and the copy_huge_page_from_user() always fails, then: > > > > > > > > ./tools/testing/selftests/vm/userfaultfd hugetlb_shared 10 > > > > 2 /tmp/kokonut_test/huge/userfaultfd_test && echo test success > > > > ./tools/testing/selftests/vm/userfaultfd hugetlb 10 > > > > 2 /tmp/kokonut_test/huge/userfaultfd_test && echo test success > > > > > > > > Both tests succeed and produce no warnings. After the > > > > test runs number of free/resv hugepages is correct. > > > > > > Many conflicts here with material that is queued for 5.14-rc1. > > > > > > How serious is this problem? Is a -stable backport warranted? > > > > > > > I've sent 2 similar patches to the list: > > > > 1. "[PATCH v4] mm, hugetlb: Fix simple resv_huge_pages underflow on UFFDIO_COPY" > > > > This one is sent to -stable and linux-mm and is a fairly simple fix. > > > > 2. "[PATCH v4] mm, hugetlb: fix racy resv_huge_pages underflow on UFFDIO_COPY" > > Ah, OK, the title of the first patch was changed, which threw me off. > > I'd skipped "[PATCH v4] mm, hugetlb: Fix simple resv_huge_pages > underflow on UFFDIO_COPY" because Mike's comments appeared to require a > v5. I applied it and made Mike's changelog suggestions. Queued for > 5.13 and -stable. > > And I queued "[PATCH v4] mm, hugetlb: fix racy resv_huge_pages > underflow on UFFDIO_COPY" for 5.14. > > Awesome, thanks! And sorry for the confusion!