Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1171796pxb; Thu, 23 Sep 2021 21:00:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwaTSchCOAiY02prTTtKt4O5TioaID0OlunR8B8jR8zVbrQzmnVtIB6YDeBFXwRrBSfJBHA X-Received: by 2002:a6b:cd43:: with SMTP id d64mr6970129iog.28.1632456002672; Thu, 23 Sep 2021 21:00:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632456002; cv=none; d=google.com; s=arc-20160816; b=n4+KcU7Fu9g3LkrYkjNOBBOQa8RsmU/qTNmFiwzYkfoZn+BOVX761U3DzW8vzyTlAq UWNfyCnq+CZ+US4uD+8LORlXMm6IDM8Ai6ju3oCnz9cAmGDoA5OrzP+f8UiHFqrFJXAT LW4hOc4ejWPKh46Zwv7RIngi2q7D5jvvlZnUWtu/SgngqpAfadXo4cyjeneFYPxgmYsz ZcKvckwqWZ5l/kn0BiphqTjEFwyq6lENrrihoxOVL2339M9s/APK0zzDFaxQJ39SZWe5 hqPQ+6MnttFtp7lHPZuX1TpEl/UCvRPHerx7hO3xd9P6ouqWv1yXKYWj2zNo6BJkFPAT yT8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=4BXd5xVDHVm4ZarnqwczzUVLSm7Xt9A4iAceJWVqj4k=; b=d2+DZ8cUkif6ucoYP5xbeTbVxDdZ8ZNsfkAltuSasByvTMRfnB6Zz9ZYGT0372Nbxq Zy7I4b2nFMvJ5SbRKfVHh7k5hgZxEb1x/n8GPw6GpDBtZvbfGNWKNjHaO+FajmeAVEmx mw8vLmQ4wPBZyvPy+kaXXgDxKwraP4h2TdcisJuVObVSls23QXWqXZJVQSt5bZ5PTLGD zRantKaOnpO5PYpX13EJAq/pjDzHoT+SlfFY1UWre7isMPAa6QLfdmpwTOtIzqTuwPso 2VL6WlKfWC/zdmy7z/x2GER0F+zPtmYt3T3+cVnWQ1kHdVEVnk6cQxZca9dYxFKTy+vE h0NQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=laalLWc0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s12si9184054iov.39.2021.09.23.20.59.50; Thu, 23 Sep 2021 21:00:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=laalLWc0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229717AbhIXEAh (ORCPT + 99 others); Fri, 24 Sep 2021 00:00:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229454AbhIXEAg (ORCPT ); Fri, 24 Sep 2021 00:00:36 -0400 Received: from mail-qt1-x830.google.com (mail-qt1-x830.google.com [IPv6:2607:f8b0:4864:20::830]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12557C061574 for ; Thu, 23 Sep 2021 20:59:04 -0700 (PDT) Received: by mail-qt1-x830.google.com with SMTP id r1so8301069qta.12 for ; Thu, 23 Sep 2021 20:59:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:in-reply-to:message-id:references :mime-version; bh=4BXd5xVDHVm4ZarnqwczzUVLSm7Xt9A4iAceJWVqj4k=; b=laalLWc0/tU2MNR97u6oy6PF6LRcbHVgVHb17kL+F7upYb+37Xb9uyutFD+jpFyoep eSSGBHQEROGXBuZL5seUlCiFFjf77mshe4fewCS4YOlkLPpktdGvVYEOi2C2XgtYKibN bg2D+awgSpl25ceIb6nPMr6n4TbTaCcvRJrs4aEZQCv5TfqMbl0VHqv+fAxgtjURzTJO 3GAbofUBIvQrn9EyKS3Kp4gErJ/NFRzHJIUTpsnT5tEF0RSswm+EZOF6XyLi3jFVZ1cP qLJxFWgrPB1iM6V6tFfYTXz3dFYmFc1dHOlKStawH6Ci3iwtYr4RurdKdwxWpuXs1vQm nPqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=4BXd5xVDHVm4ZarnqwczzUVLSm7Xt9A4iAceJWVqj4k=; b=vQ8teCmTA6qIOWd7CqIEPPiXvOKSixyotWdxku+Wwo80hC+zPVSVODUK3mlnOrhkwX FWFfFs1DyP58yFGITq0p5IiVU5wkEcZ/IiUYVAAZDP0rrz8+ErHWlDu7lLWK+8eJvHHm R4IausFm62+gDj/iFB8eF3+AGW0EJoeJt048g+VwKFprkqfQEENCkCpW01VD98/6DpVK 8LvAxz+xh6I/O2IRm76LbFNt9yg7kKaMwqEn3vS9n2boUE0wlP3IV6RMpXea4AVsLr8E 2lTzJjrs8NrYgmCtiNlTZ/rNaiQcOkp0L2I00S3ydkyxfRZmuL8IP8Ra/e86EGIV5GhJ uGBQ== X-Gm-Message-State: AOAM532Pc6h4N25JtTjq221ie73nfdsvDcu/u322lb59CHuOLkAXhLEU /AZn/QCIUwR8eHPHhlBg6ZpyfW4GrLxv3A== X-Received: by 2002:ac8:60d9:: with SMTP id i25mr2149855qtm.406.1632455943052; Thu, 23 Sep 2021 20:59:03 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id x3sm5516825qkl.107.2021.09.23.20.59.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Sep 2021 20:59:02 -0700 (PDT) Date: Thu, 23 Sep 2021 20:59:00 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Peter Xu cc: linux-kernel@vger.kernel.org, Andrew Morton , linux-mm@kvack.org, Hugh Dickins , David Hildenbrand , Liam Howlett , Mike Rapoport , Alistair Popple , Matthew Wilcox , Yang Shi , "Kirill A . Shutemov" , Jerome Glisse , Miaohe Lin , Andrea Arcangeli Subject: Re: [PATCH v4 2/4] mm: Clear vmf->pte after pte_unmap_same() returns In-Reply-To: <20210915181533.11188-1-peterx@redhat.com> Message-ID: <7b877ef5-9dd5-97ed-dd1a-36dbf5d02547@google.com> References: <20210915181456.10739-1-peterx@redhat.com> <20210915181533.11188-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 15 Sep 2021, Peter Xu wrote: > pte_unmap_same() will always unmap the pte pointer. After the unmap, vmf->pte > will not be valid any more, we should clear it. > > It was safe only because no one is accessing vmf->pte after pte_unmap_same() > returns, since the only caller of pte_unmap_same() (so far) is do_swap_page(), > where vmf->pte will in most cases be overwritten very soon. > > Directly pass in vmf into pte_unmap_same() and then we can also avoid the long > parameter list too, which should be a nice cleanup. > > Reviewed-by: Miaohe Lin > Reviewed-by: David Hildenbrand > Reviewed-by: Liam Howlett > Signed-off-by: Peter Xu This one seems fine, thanks. Acked-by: Hugh Dickins > --- > mm/memory.c | 12 ++++++------ > 1 file changed, 6 insertions(+), 6 deletions(-) > > diff --git a/mm/memory.c b/mm/memory.c > index 25fc46e87214..7b095f07c4ef 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -2724,19 +2724,19 @@ EXPORT_SYMBOL_GPL(apply_to_existing_page_range); > * proceeding (but do_wp_page is only called after already making such a check; > * and do_anonymous_page can safely check later on). > */ > -static inline int pte_unmap_same(struct mm_struct *mm, pmd_t *pmd, > - pte_t *page_table, pte_t orig_pte) > +static inline int pte_unmap_same(struct vm_fault *vmf) > { > int same = 1; > #if defined(CONFIG_SMP) || defined(CONFIG_PREEMPTION) > if (sizeof(pte_t) > sizeof(unsigned long)) { > - spinlock_t *ptl = pte_lockptr(mm, pmd); > + spinlock_t *ptl = pte_lockptr(vmf->vma->vm_mm, vmf->pmd); > spin_lock(ptl); > - same = pte_same(*page_table, orig_pte); > + same = pte_same(*vmf->pte, vmf->orig_pte); > spin_unlock(ptl); > } > #endif > - pte_unmap(page_table); > + pte_unmap(vmf->pte); > + vmf->pte = NULL; > return same; > } > > @@ -3487,7 +3487,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) > vm_fault_t ret = 0; > void *shadow = NULL; > > - if (!pte_unmap_same(vma->vm_mm, vmf->pmd, vmf->pte, vmf->orig_pte)) > + if (!pte_unmap_same(vmf)) > goto out; > > entry = pte_to_swp_entry(vmf->orig_pte); > -- > 2.31.1