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 5C235C433FE for ; Thu, 3 Nov 2022 15:39:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C6DF86B0072; Thu, 3 Nov 2022 11:39:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C1E526B0073; Thu, 3 Nov 2022 11:39:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AE57B6B0074; Thu, 3 Nov 2022 11:39:09 -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 9D4616B0072 for ; Thu, 3 Nov 2022 11:39:09 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 74A3DA132C for ; Thu, 3 Nov 2022 15:39:09 +0000 (UTC) X-FDA: 80092539618.24.4CA780E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf13.hostedemail.com (Postfix) with ESMTP id BE97E2000A for ; Thu, 3 Nov 2022 15:39:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667489948; 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=FCO0eVFO3uvEok1cguH8xZ0emQ98va1B5hUX7PNPCwA=; b=TdukN2kV6i2qTTnT2WFd2cVs5IhgxNnIiP9qbsgOyzGZbuU5U6ZI9u9L5Y8Z+xxYg8BEZK 7uBzr8fLETW1EwZ90jEdfsqAXK83vFir3gQVO+moWfAbVW89hiheoyTxPI3zPxgUx/JzPJ 4o78kHfZrpv1bXvWeHpd7w6VusFF+1E= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-253-fIjdj4K0PLOagiGtQUnRDQ-1; Thu, 03 Nov 2022 11:39:07 -0400 X-MC-Unique: fIjdj4K0PLOagiGtQUnRDQ-1 Received: by mail-qt1-f197.google.com with SMTP id gc12-20020a05622a59cc00b003a5444280e1so2069557qtb.13 for ; Thu, 03 Nov 2022 08:39:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=FCO0eVFO3uvEok1cguH8xZ0emQ98va1B5hUX7PNPCwA=; b=bpFvq5b6Qz7yXU4qRTxIjtOBzzRRQjrXufg6mhxV6b4CxTRXkBVZZ+cAfY245h5Of3 6ww0B8UGliWXpNxejiMz38sj9o07BzZ64CE8cRRliVkwC6MgnomeAEx8ZkvZXc2+EG+r RSodeVMUW4HwP2B1H7JNbN+++tYgRgRjTUKyLtAEo6EJRGUmMS4AUL48nv7PBSDtIN0a Uo6gTHJPcgutoxH3bP3L1gn6LW5ufdulD087ld4fmhFB22LaWW7dfJKJQIXdl0OGNw10 uJ45gnnu5576e2ITFxgdwUXCpan61/f34zzb1tQGyB2KbDpdCMB/C6VA3OUmP/X49X+b DBsA== X-Gm-Message-State: ACrzQf2IyTn09Q0LzwNku3/oHLZq+gRv0ipLZmguRwYzCzFTQ8wNTqz0 7iarEUrcW1ooTNYaU4DKBYDS8jw506m4PCCNKCwQGbyEX/3c0L0kuiV5b1j0N1U83B0cMIk7tKs 4JJbiOPqkT4s= X-Received: by 2002:a05:620a:1a14:b0:6ce:a65b:8e6 with SMTP id bk20-20020a05620a1a1400b006cea65b08e6mr22646406qkb.145.1667489946731; Thu, 03 Nov 2022 08:39:06 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5Bes9+1WNllEELeLCD5AFB3zKvZwG1Ig3CdThVFvTsMP3GaaDsEqnyg3zz0l+66R5s+diOoA== X-Received: by 2002:a05:620a:1a14:b0:6ce:a65b:8e6 with SMTP id bk20-20020a05620a1a1400b006cea65b08e6mr22646383qkb.145.1667489946469; Thu, 03 Nov 2022 08:39:06 -0700 (PDT) Received: from x1n (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id u22-20020a05620a431600b006cdd0939ffbsm936018qko.86.2022.11.03.08.39.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 08:39:05 -0700 (PDT) Date: Thu, 3 Nov 2022 11:39:04 -0400 From: Peter Xu To: James Houghton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Mike Kravetz , David Hildenbrand , Andrea Arcangeli , Rik van Riel , Andrew Morton , Muchun Song , Miaohe Lin , Nadav Amit Subject: Re: [PATCH RFC 09/10] mm/hugetlb: Make hugetlb_fault() RCU-safe Message-ID: References: <20221030212929.335473-1-peterx@redhat.com> <20221030213043.335669-1-peterx@redhat.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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667489949; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=FCO0eVFO3uvEok1cguH8xZ0emQ98va1B5hUX7PNPCwA=; b=BHGFEw/OoTLSgYOhBydu82Rj90rUXYBgJX4Uw3hsEkZseoPRzLtqnOMG14PPhppfr+aJPZ d3G8yriZR/Xk/Y3psYYEaq152VAoO6cu5OM1W2pf9te0qC1tALmzf2piBJXD8m+SHUXF64 lxTbh2iaXSByPEmUoYkjcR4Q1/yjrLc= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TdukN2kV; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf13.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667489949; a=rsa-sha256; cv=none; b=k7AfBJ48A9DuNFurBeTL0vLeYId2jTBDdHZmollanM32zsuxEpGNTwfEJeLh6V9zKC4OMK OSfwYdEv63zo9eXY2C2amf3oI2U1k3YymRFR9LbUja1mG1UN+xmM+wplM5SfZ9gj0LdP3a 4jk/qxKUKy5kkEMlCs/5qnmcsmNqcME= Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TdukN2kV; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf13.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com X-Rspam-User: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: BE97E2000A X-Stat-Signature: hxnehu9obuxsemsrau1fja4bufs775je X-HE-Tag: 1667489948-677212 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 Wed, Nov 02, 2022 at 11:04:01AM -0700, James Houghton wrote: > On Sun, Oct 30, 2022 at 2:30 PM Peter Xu wrote: > > > > RCU makes sure the pte_t* won't go away from under us. Please refer to the > > comment above huge_pte_offset() for more information. > > Thanks for this series, Peter! :) Thanks for reviewing, James! > > > > > Signed-off-by: Peter Xu > > --- > > mm/hugetlb.c | 6 +++++- > > 1 file changed, 5 insertions(+), 1 deletion(-) > > > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > > index 5dc87e4e6780..6d336d286394 100644 > > --- a/mm/hugetlb.c > > +++ b/mm/hugetlb.c > > @@ -5822,6 +5822,8 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, > > int need_wait_lock = 0; > > unsigned long haddr = address & huge_page_mask(h); > > > > + /* For huge_pte_offset() */ > > + rcu_read_lock(); > > ptep = huge_pte_offset(mm, haddr, huge_page_size(h)); > > if (ptep) { > > /* > > @@ -5830,13 +5832,15 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, > > * not actually modifying content here. > > */ > > entry = huge_ptep_get(ptep); > > + rcu_read_unlock(); > > if (unlikely(is_hugetlb_entry_migration(entry))) { > > migration_entry_wait_huge(vma, ptep); > > ptep is used here (and we dereference it in > `__migration_entry_wait_huge`), so this looks unsafe to me. A simple > way to fix this would be to move the migration entry check after the > huge_pte_alloc call. Right, I definitely overlooked the migration entries in both patches (including the previous one that you commented), thanks for pointing that out. Though moving that after huge_pte_alloc() may have similar problem, iiuc. The thing is we need either the vma lock or rcu to protect accessing the pte*, while the pte* page and its pgtable lock can be accessed very deep into the migration core (e.g., migration_entry_wait_on_locked()) as the lock cannot be released before the thread queues itself into the waitqueue. So far I don't see a good way to achieve this but add a hook to migration_entry_wait_on_locked() so that any lock held for huge migrations can be properly released after the pgtable lock released but before the thread yields itself. -- Peter Xu