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=-11.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 1CBA4C433B4 for ; Wed, 12 May 2021 20:14:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 967E1613FB for ; Wed, 12 May 2021 20:14:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 967E1613FB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0E4476B0072; Wed, 12 May 2021 16:14:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 06C0C6B0073; Wed, 12 May 2021 16:14:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E00876B0074; Wed, 12 May 2021 16:14:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0022.hostedemail.com [216.40.44.22]) by kanga.kvack.org (Postfix) with ESMTP id AC0DD6B0072 for ; Wed, 12 May 2021 16:14:49 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 4CB21181AF5C2 for ; Wed, 12 May 2021 20:14:49 +0000 (UTC) X-FDA: 78133682298.05.D25E48E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf17.hostedemail.com (Postfix) with ESMTP id 6458A407F8FF for ; Wed, 12 May 2021 20:14:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620850487; 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: in-reply-to:in-reply-to:references:references; bh=3wuTWQtuAdZWIF9OysD2QPM7zsLn8CRp+0adiSduMjY=; b=cKuSYSBmxsZMEzJGxZf5ZXgD21p1MdO60uzzhSmYnfhJuIiz3+YC5NpR+tEp/A07AU98jQ zKNJnjvV+rVXM+ElbjzEULdLERo9YQIFXT68+tqjRIBTKQsYMsjlI1IiP9wOuLcxzXZoAz sRrOQnQB5jrmTT1wIZZvfuCDRVrYAAo= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-372-tA14DAUMOaO796DhZOZcaQ-1; Wed, 12 May 2021 16:14:43 -0400 X-MC-Unique: tA14DAUMOaO796DhZOZcaQ-1 Received: by mail-qk1-f200.google.com with SMTP id i141-20020a379f930000b02902e94f6d938dso18134600qke.5 for ; Wed, 12 May 2021 13:14:43 -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=3wuTWQtuAdZWIF9OysD2QPM7zsLn8CRp+0adiSduMjY=; b=DSJyowJd5oKwAtYEWepH8ljnnbv7iTbtjSEpoSWDAMZTMsCEGwsub43GNv1pvK+WQ6 BuNSQvfkk8kX2Qj6Ly+kXwM/yhS+3v6Ij+AqxePpgZpCJhl7+d1SHGSYt+zBEJngI7d1 BlfCeQfa581LXH9t7082w1roEhVIQORFNm0x6ZGFwJR9LtCZOpR+HDgWiFrdm/IKMxmW WLe4IQ/TrGYylgAZ9kLutSTttFMhcAupZQnuJNpv/+q57qKYN8NlK8ufnGtuYewLLFfs M83838M9HSnfiuJevgx5xpaYmYsMONHTLecgTtdcBDb2eV5MS2Ay29wzj9P58s4UadYd vndg== X-Gm-Message-State: AOAM533jxEYxQyllQ4lR+lU8/2XKs90uPgchPlDJdNCoto1DvLJOcfW4 G5Go/DAp0TlYGeargypkXuNpBQ/x9VDbBPKTYAPa8C7DXtkUsng2jSUA+9SuCEm9kBh/WasqSsP XmePOzj1atOY= X-Received: by 2002:ac8:754a:: with SMTP id b10mr35375894qtr.83.1620850483239; Wed, 12 May 2021 13:14:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyFVH3v9wK01tFnKp9M4XThk+XsejO1huyQYVMBeEOp+qXQ8jQRLoYuAI5nciOv1HySxPSwOA== X-Received: by 2002:ac8:754a:: with SMTP id b10mr35375872qtr.83.1620850482957; Wed, 12 May 2021 13:14:42 -0700 (PDT) Received: from t490s (bras-base-toroon474qw-grc-72-184-145-4-219.dsl.bell.ca. [184.145.4.219]) by smtp.gmail.com with ESMTPSA id h10sm884015qka.26.2021.05.12.13.14.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 May 2021 13:14:42 -0700 (PDT) Date: Wed, 12 May 2021 16:14:40 -0400 From: Peter Xu To: Mina Almasry Cc: Mike Kravetz , Andrew Morton , Linux-MM , open list , Axel Rasmussen Subject: Re: [PATCH] mm, hugetlb: fix resv_huge_pages underflow on UFFDIO_COPY Message-ID: References: <20210512065813.89270-1-almasrymina@google.com> MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cKuSYSBm; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf17.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=peterx@redhat.com X-Stat-Signature: royq7ddrhgznq16kpkh4yuz8y4xxkmkx X-Rspamd-Queue-Id: 6458A407F8FF X-Rspamd-Server: rspam02 Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf17; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=170.10.133.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1620850482-850073 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: Mina, On Wed, May 12, 2021 at 12:42:32PM -0700, Mina Almasry wrote: > > >> @@ -4868,30 +4869,39 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, > > >> struct page **pagep) > > >> { > > >> bool is_continue = (mode == MCOPY_ATOMIC_CONTINUE); > > >> - struct address_space *mapping; > > >> - pgoff_t idx; > > >> + struct hstate *h = hstate_vma(dst_vma); > > >> + struct address_space *mapping = dst_vma->vm_file->f_mapping; > > >> + pgoff_t idx = vma_hugecache_offset(h, dst_vma, dst_addr); > > >> unsigned long size; > > >> int vm_shared = dst_vma->vm_flags & VM_SHARED; > > >> - struct hstate *h = hstate_vma(dst_vma); > > >> pte_t _dst_pte; > > >> spinlock_t *ptl; > > >> - int ret; > > >> + int ret = -ENOMEM; > > >> struct page *page; > > >> int writable; > > >> > > >> - mapping = dst_vma->vm_file->f_mapping; > > >> - idx = vma_hugecache_offset(h, dst_vma, dst_addr); > > >> + /* Out parameter. */ > > >> + WARN_ON(*pagep); > > > > > > I don't think this warning works, because we do set *pagep, in the > > > copy_huge_page_from_user failure case. In that case, the following > > > happens: > > > > > > 1. We set *pagep, and return immediately. > > > 2. Our caller notices this particular error, drops mmap_lock, and then > > > calls us again with *pagep set. > > > > > > In this path, we're supposed to just re-use this existing *pagep > > > instead of allocating a second new page. > > > > > > I think this also means we need to keep the "else" case where *pagep > > > is set below. > > > > > > > +1 to Peter's comment. > > > > Gah, sorry about that. I'll fix in v2. I have a question regarding v1: how do you guarantee huge_add_to_page_cache() won't fail again even if checked before page alloc? Say, what if the page cache got inserted after hugetlbfs_pagecache_present() (which is newly added in your v1) but before huge_add_to_page_cache()? I also have a feeling that we've been trying to work around something else, but I can't tell yet as I'll probably need to read a bit more/better on how hugetlb does the accounting and also on reservations. Thanks, -- Peter Xu