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=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 9E4C1C433F5 for ; Wed, 15 Sep 2021 18:15:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 49867611C4 for ; Wed, 15 Sep 2021 18:15:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 49867611C4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id E504D6B0073; Wed, 15 Sep 2021 14:15:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DFFFB6B0074; Wed, 15 Sep 2021 14:15:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CA1356B0075; Wed, 15 Sep 2021 14:15:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0020.hostedemail.com [216.40.44.20]) by kanga.kvack.org (Postfix) with ESMTP id BAE756B0073 for ; Wed, 15 Sep 2021 14:15:38 -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 BDEA018019575 for ; Wed, 15 Sep 2021 18:15:37 +0000 (UTC) X-FDA: 78590610714.05.CD41757 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf25.hostedemail.com (Postfix) with ESMTP id 6137DB000186 for ; Wed, 15 Sep 2021 18:15:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631729736; 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=yCBcgdQfSQO0vdlLaUvPYqHDlVPUHtkRpfsoC2DOf1s=; b=Mf/QXWxkd/4ede/TsgVli6b5AUOTiC3X3ODlHnZta/hMSiDROXn/fR5xh+echarxA5MiEN ZICCnXYsn+tCvFtZgniwIM6+Sh3YYF1CHg4hdthGISHMix8ECW2AGurt/udvG9f2lLIjrC lrjVsMdTHSF780yptUHIOfzngif8Ack= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-42-HVylwxcsMgqlBfRKfut6og-1; Wed, 15 Sep 2021 14:15:36 -0400 X-MC-Unique: HVylwxcsMgqlBfRKfut6og-1 Received: by mail-qv1-f72.google.com with SMTP id ib9-20020a0562141c8900b003671c3a1243so6447116qvb.21 for ; Wed, 15 Sep 2021 11:15:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yCBcgdQfSQO0vdlLaUvPYqHDlVPUHtkRpfsoC2DOf1s=; b=dvbtYwqQJ8zYkDMYgHDmMEtgtIfIyf7TiRXzjlb3apRB76zHG6bObtJCg65t6Y4knW aB8f/7LzR4YOR5GXoWWRdLR+aObE4su6hSeQzZV0iLC5BAAKp58CB/rPj/hJCHFlCsNR nX9fbAGbAywnTTxT62+bdb4pf27ah+1CRaQPlgd+6Xyq+F9z1OI2T3aCZ1QQayKxxMUj fmGMZ0EAQg7bm6aIauGm5GwvoF4XF0ZSL2HcDTp9aJAQTgpbiNEzhrHgPbhmibe5hF2D dh9Mk0wMy30nIM6MQoND6BzVrJ/qMs4Ge9jiWNqn7ApIsiq+66ui3z3vhsl0XJhLBwf6 jBNA== X-Gm-Message-State: AOAM532R8kiLM3awbaK8RstdW+P1Y66R6VDeBMWDdmhly40BNPxLlpxH DgflBf+UmGYb4/2pALaTJbuZGQbR1gVAp4O9cjfouYqZZcJkTvP+AB/sfFmj12InE2oxN59RYLZ pjjBJFlpoRnA= X-Received: by 2002:ae9:e858:: with SMTP id a85mr1259140qkg.97.1631729735530; Wed, 15 Sep 2021 11:15:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNOKoWdJ3QZ+W2MJPuiiol1pHZKM860TkZUW+41Zl1wmq7UcHBNIiRCGRpEP4med2lISCytQ== X-Received: by 2002:ae9:e858:: with SMTP id a85mr1259106qkg.97.1631729735316; Wed, 15 Sep 2021 11:15:35 -0700 (PDT) Received: from t490s.redhat.com ([2607:fea8:56a2:9100::d35a]) by smtp.gmail.com with ESMTPSA id a9sm554724qko.27.2021.09.15.11.15.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Sep 2021 11:15:34 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, Andrew Morton , linux-mm@kvack.org Cc: Hugh Dickins , David Hildenbrand , Liam Howlett , Mike Rapoport , Alistair Popple , Matthew Wilcox , peterx@redhat.com, Yang Shi , "Kirill A . Shutemov" , Jerome Glisse , Miaohe Lin , Andrea Arcangeli Subject: [PATCH v4 2/4] mm: Clear vmf->pte after pte_unmap_same() returns Date: Wed, 15 Sep 2021 14:15:33 -0400 Message-Id: <20210915181533.11188-1-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210915181456.10739-1-peterx@redhat.com> References: <20210915181456.10739-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="US-ASCII" Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="Mf/QXWxk"; spf=none (imf25.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Stat-Signature: 7oqasd1eg5i1oa3unatb5b4ikma6qj98 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 6137DB000186 X-HE-Tag: 1631729737-953404 Content-Transfer-Encoding: quoted-printable 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: 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_sam= e() returns, since the only caller of pte_unmap_same() (so far) is do_swap_pa= ge(), 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 --- 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 =3D 1; #if defined(CONFIG_SMP) || defined(CONFIG_PREEMPTION) if (sizeof(pte_t) > sizeof(unsigned long)) { - spinlock_t *ptl =3D pte_lockptr(mm, pmd); + spinlock_t *ptl =3D pte_lockptr(vmf->vma->vm_mm, vmf->pmd); spin_lock(ptl); - same =3D pte_same(*page_table, orig_pte); + same =3D pte_same(*vmf->pte, vmf->orig_pte); spin_unlock(ptl); } #endif - pte_unmap(page_table); + pte_unmap(vmf->pte); + vmf->pte =3D NULL; return same; } =20 @@ -3487,7 +3487,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) vm_fault_t ret =3D 0; void *shadow =3D NULL; =20 - if (!pte_unmap_same(vma->vm_mm, vmf->pmd, vmf->pte, vmf->orig_pte)) + if (!pte_unmap_same(vmf)) goto out; =20 entry =3D pte_to_swp_entry(vmf->orig_pte); --=20 2.31.1