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 77347C433F5 for ; Fri, 29 Apr 2022 09:48:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 014186B0071; Fri, 29 Apr 2022 05:48:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F06C66B0073; Fri, 29 Apr 2022 05:48:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DF5356B0074; Fri, 29 Apr 2022 05:48:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id D10B96B0071 for ; Fri, 29 Apr 2022 05:48:47 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 9F9D980E15 for ; Fri, 29 Apr 2022 09:48:47 +0000 (UTC) X-FDA: 79409442294.26.1E85413 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf27.hostedemail.com (Postfix) with ESMTP id 8D9E040053 for ; Fri, 29 Apr 2022 09:48:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651225726; 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=OG90F21ilKlDNtjgRsqpwUPxSnJdXSSgvFpobfkqunQ=; b=WeXzV5+Cr/tcA/9s8T7c+t5LE2wFhVKWy5vEHBvZxsUnyy1rTH2j4RU1E+rvzVGOy7dedh pKsSG3wZAG9J5wzvZ9fe8GqcnZONJddVMfHz8kTGOcXiTfjppKpJ0AVX8jPBkCz95rfKHp a3bkKx/3auB76iiQbat4kkfIjddVqnI= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-663-lX_5woYgOdulxiFkLnSrgg-1; Fri, 29 Apr 2022 05:48:45 -0400 X-MC-Unique: lX_5woYgOdulxiFkLnSrgg-1 Received: by mail-wm1-f69.google.com with SMTP id v191-20020a1cacc8000000b0038ce818d2efso2770298wme.1 for ; Fri, 29 Apr 2022 02:48:45 -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:subject :content-language:to:cc:references:from:organization:in-reply-to :content-transfer-encoding; bh=OG90F21ilKlDNtjgRsqpwUPxSnJdXSSgvFpobfkqunQ=; b=ZBmpmi8CLD4bX01z8sctvEtJdcfyjWOufp52btNfRy3TDzMyFF9upxQE8AIaGQ0Iy9 Jvf9Lr3rix8UPndqW09EOg285KQ2bOVQljgam4I/vEJTuLaAgMLmhsNV0/e4yMGGNwnn fBeYPVKURamYSFz8uNj2Z/xXv5LDwW3/hV0LnO1cFY4aHsmb8WCnXteBExgJmkdA62/2 hTno3cgHFiJLaDZkUuAfsemx12l9e7yXJz9GuoZmvEeqINzeFf2BMWJTjUnGr80blY+D RH4lUNOwZbBPG0IQT4WBFWX8gISxA2rx2/rIuTwAjzCwkKsax9vOWq8JgjovwxxRnT72 sySQ== X-Gm-Message-State: AOAM531NOl0og797q9tCTGOF3rOr+CfUK8qAfwk04EBxYgVb2VzAdGJ0 SWMKhgVrkgBixGPUdFBGcVRkL1YpTy6OiFvURR8W+VUyO9YSuYzmywCjhGwQolnDzr3HD+9dIKh wKBsG8AtybXs= X-Received: by 2002:a1c:e916:0:b0:38e:ac96:f477 with SMTP id q22-20020a1ce916000000b0038eac96f477mr2386085wmc.160.1651225724192; Fri, 29 Apr 2022 02:48:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyc32NA/ClnmuNmccycfutXjbZtcGqyD1urDez24X9yKDxfuY7A2fS+Lv19Aw+r6DMbRCHLTg== X-Received: by 2002:a1c:e916:0:b0:38e:ac96:f477 with SMTP id q22-20020a1ce916000000b0038eac96f477mr2386071wmc.160.1651225723957; Fri, 29 Apr 2022 02:48:43 -0700 (PDT) Received: from ?IPV6:2003:cb:c707:fe00:bbeb:98e6:617a:dea1? (p200300cbc707fe00bbeb98e6617adea1.dip0.t-ipconnect.de. [2003:cb:c707:fe00:bbeb:98e6:617a:dea1]) by smtp.gmail.com with ESMTPSA id p6-20020a05600c358600b00393eaf94077sm2824722wmq.8.2022.04.29.02.48.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 29 Apr 2022 02:48:43 -0700 (PDT) Message-ID: Date: Fri, 29 Apr 2022 11:48:42 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.2 Subject: Re: [PATCH v2 4/4] mm/migration: fix potential pte_unmap on an not mapped pte To: Miaohe Lin , akpm@linux-foundation.org, mike.kravetz@oracle.com, naoya.horiguchi@nec.com Cc: ying.huang@intel.com, hch@lst.de, dhowells@redhat.com, cl@linux.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20220425132723.34824-1-linmiaohe@huawei.com> <20220425132723.34824-5-linmiaohe@huawei.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: <20220425132723.34824-5-linmiaohe@huawei.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=WeXzV5+C; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf27.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=david@redhat.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 8D9E040053 X-Rspam-User: X-Stat-Signature: eum77ge3josuq9gteqpmfuufkay5rhye X-HE-Tag: 1651225725-81746 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 25.04.22 15:27, Miaohe Lin wrote: > __migration_entry_wait and migration_entry_wait_on_locked assume pte is > always mapped from caller. But this is not the case when it's called from > migration_entry_wait_huge and follow_huge_pmd. Add a hugetlbfs variant that > calls hugetlb_migration_entry_wait(ptep == NULL) to fix this issue. > > Fixes: 30dad30922cc ("mm: migration: add migrate_entry_wait_huge()") > Suggested-by: David Hildenbrand > Signed-off-by: Miaohe Lin > --- > include/linux/swapops.h | 12 ++++++++---- > mm/hugetlb.c | 4 ++-- > mm/migrate.c | 23 +++++++++++++++++++---- > 3 files changed, 29 insertions(+), 10 deletions(-) > > diff --git a/include/linux/swapops.h b/include/linux/swapops.h > index 30cded849ee4..862e5a2053b1 100644 > --- a/include/linux/swapops.h > +++ b/include/linux/swapops.h > @@ -244,8 +244,10 @@ extern void __migration_entry_wait(struct mm_struct *mm, pte_t *ptep, > spinlock_t *ptl); > extern void migration_entry_wait(struct mm_struct *mm, pmd_t *pmd, > unsigned long address); > -extern void migration_entry_wait_huge(struct vm_area_struct *vma, > - struct mm_struct *mm, pte_t *pte); > +#ifdef CONFIG_HUGETLB_PAGE > +extern void __migration_entry_wait_huge(pte_t *ptep, spinlock_t *ptl); > +extern void migration_entry_wait_huge(struct vm_area_struct *vma, pte_t *pte); > +#endif > #else > static inline swp_entry_t make_readable_migration_entry(pgoff_t offset) > { > @@ -271,8 +273,10 @@ static inline void __migration_entry_wait(struct mm_struct *mm, pte_t *ptep, > spinlock_t *ptl) { } > static inline void migration_entry_wait(struct mm_struct *mm, pmd_t *pmd, > unsigned long address) { } > -static inline void migration_entry_wait_huge(struct vm_area_struct *vma, > - struct mm_struct *mm, pte_t *pte) { } > +#ifdef CONFIG_HUGETLB_PAGE > +static inline void __migration_entry_wait_huge(pte_t *ptep, spinlock_t *ptl) { } > +static inline void migration_entry_wait_huge(struct vm_area_struct *vma, pte_t *pte) { } > +#endif > static inline int is_writable_migration_entry(swp_entry_t entry) > { > return 0; > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index 098f81e8550d..994361ec75e0 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -5689,7 +5689,7 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, > */ > entry = huge_ptep_get(ptep); > if (unlikely(is_hugetlb_entry_migration(entry))) { > - migration_entry_wait_huge(vma, mm, ptep); > + migration_entry_wait_huge(vma, ptep); > return 0; > } else if (unlikely(is_hugetlb_entry_hwpoisoned(entry))) > return VM_FAULT_HWPOISON_LARGE | > @@ -6907,7 +6907,7 @@ follow_huge_pmd(struct mm_struct *mm, unsigned long address, > } else { > if (is_hugetlb_entry_migration(pte)) { > spin_unlock(ptl); > - __migration_entry_wait(mm, (pte_t *)pmd, ptl); > + __migration_entry_wait_huge((pte_t *)pmd, ptl); The unlock+immediate relock looks a bit sub-optimal, but that's already been that way before your change. Reviewed-by: David Hildenbrand -- Thanks, David / dhildenb