Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1567966rdh; Mon, 25 Sep 2023 17:48:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEKS1e5lQT1oOg0+5xJmZLXZX+EVuJ7BYKpu5w3QraoXDB0MESZY+vXXHqav3wbluMncdkM X-Received: by 2002:a05:6808:191c:b0:3a7:1278:1899 with SMTP id bf28-20020a056808191c00b003a712781899mr13777589oib.15.1695689301918; Mon, 25 Sep 2023 17:48:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695689301; cv=none; d=google.com; s=arc-20160816; b=ZhIiNYtrzE60uEzl55I31qk9g9eVtHXjhGvFhpbxjqPYKtDET6O/Bp1B1hCcLwg7Go x0LH+g0esEgr+IEGc3/3nfLhdMwupWr+xPNHL63n2yGxao79OJoYnzWbK5pri7UNLQfU S0RmZHJCWek4Pgvzn4Epb5sNTm2gGRes/jAqg8j9bpD08IVAQySseAi5I+lHmpKwMGv3 CWq3R0x+Tfmt3KOxjX7FcXMVGjTeDwxIiB7zgXUEE/RbyV+8WxMzuxtH0jE4BiXGe66H OPCftFDPfNEzeSq4naggnA5sG+lrsIFXvEIksbVtzN3WZjUKdfK+0A0Y4js1dXf9GFmu rNXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id; bh=9zA70boYEMABbGGID/mwC5OVtX6FfCrP9EDcl6EYUEk=; fh=hOaN1/HlXWrx/vHluPQdqKKg6VbIVLaMJV2uvguRs3c=; b=b5Mw8WE51Jcdrxna0+qrywKJnWTjFWNnR9IF8peoEBCflmQnoYLp/jU1abeH43G+H0 qxaeqicpRlAjLjsav1FSlawEGnhWJv7yENyA8VhT4o8VopV4L6yob7f7y2YZBVpSoItA ov8UJMQeV6IC7lkAmjSACIcajMWX4CpTpZ6vchwxPzcFdA+rDtYcOW2egB63IbmQC3Ka G8Gj3OI64j78yn4tAGkPEiYIwH/L/PbepPtOsFGPmWR8NprIMMAHBuje0aE3hFajH+GL ChfYexq6nlMAjrAwEPSvpLnNU7hD9C5M4dNrppdLwTNUZ8Y6rFxzgEMJw1hfnQjHl8+n 0HUQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id z189-20020a6333c6000000b00573efae0ee1si459561pgz.515.2023.09.25.17.48.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 17:48:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id E276E819D9CD; Mon, 25 Sep 2023 17:47:42 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231767AbjIZAro convert rfc822-to-8bit (ORCPT + 99 others); Mon, 25 Sep 2023 20:47:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229495AbjIZArn (ORCPT ); Mon, 25 Sep 2023 20:47:43 -0400 Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6702109 for ; Mon, 25 Sep 2023 17:47:36 -0700 (PDT) Received: from imladris.home.surriel.com ([10.0.13.28] helo=imladris.surriel.com) by shelob.surriel.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1qkwE0-0000aR-1t; Mon, 25 Sep 2023 20:46:52 -0400 Message-ID: <3b7221768bebd9cac5ab8004dca901c4f2faf3cb.camel@surriel.com> Subject: Re: [PATCH 2/3] hugetlbfs: close race between MADV_DONTNEED and page fault From: Rik van Riel To: Mike Kravetz Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, linux-mm@kvack.org, akpm@linux-foundation.org, muchun.song@linux.dev, leit@meta.com, willy@infradead.org Date: Mon, 25 Sep 2023 20:46:52 -0400 In-Reply-To: <20230925222539.GC11309@monkey> References: <20230925203030.703439-1-riel@surriel.com> <20230925203030.703439-3-riel@surriel.com> <20230925222539.GC11309@monkey> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT User-Agent: Evolution 3.46.4 (3.46.4-1.fc37) MIME-Version: 1.0 Sender: riel@surriel.com X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Mon, 25 Sep 2023 17:47:43 -0700 (PDT) On Mon, 2023-09-25 at 15:25 -0700, Mike Kravetz wrote: > On 09/25/23 16:28, riel@surriel.com wrote: > > > > -void __unmap_hugepage_range_final(struct mmu_gather *tlb, > > -                         struct vm_area_struct *vma, unsigned long > > start, > > -                         unsigned long end, struct page *ref_page, > > -                         zap_flags_t zap_flags) > > +void __hugetlb_zap_begin(struct vm_area_struct *vma, > > +                        unsigned long *start, unsigned long *end) > >  { > > +       adjust_range_if_pmd_sharing_possible(vma, start, end); > >         hugetlb_vma_lock_write(vma); > >         i_mmap_lock_write(vma->vm_file->f_mapping); > > +} > > __unmap_hugepage_range_final() was called from unmap_single_vma. > unmap_single_vma has two callers, zap_page_range_single and > unmap_vmas. > > When the locking was moved into hugetlb_zap_begin, it was only added > to the > zap_page_range_single call path.  Calls from unmap_vmas are missing > the > locking. Oh, that's a fun one. I suppose the locking of the f_mapping lock, and calling adjust_range_if_pmd_sharing_possible matters for the call from unmap_vmas, while the call tho hugetlb_vma_lock_write really doesn't matter, since unmap_vmas is called with the mmap_sem held for write, which already excludes page faults. I'll add the call there for v4. Good catch. -- All Rights Reversed.