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.6 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,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 2BBAAC433E0 for ; Fri, 15 Jan 2021 17:09:27 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D635B2333E for ; Fri, 15 Jan 2021 17:09:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D635B2333E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A8CD58D019F; Fri, 15 Jan 2021 12:09:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A3CD68D019D; Fri, 15 Jan 2021 12:09:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8B4FE8D019F; Fri, 15 Jan 2021 12:09:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0104.hostedemail.com [216.40.44.104]) by kanga.kvack.org (Postfix) with ESMTP id 731EE8D019D for ; Fri, 15 Jan 2021 12:09:23 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 3ACFD181AEF39 for ; Fri, 15 Jan 2021 17:09:23 +0000 (UTC) X-FDA: 77708645406.15.shock17_5808f4827531 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin15.hostedemail.com (Postfix) with ESMTP id 10D2818149036 for ; Fri, 15 Jan 2021 17:09:23 +0000 (UTC) X-HE-Tag: shock17_5808f4827531 X-Filterd-Recvd-Size: 6150 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Fri, 15 Jan 2021 17:09:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610730561; 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=PCE2jOXT0VlYi8yeqH5i2c+Kk2ht8PluAgOmKW/+jmU=; b=TJwxJb1WtuXJJ2h0qY2CfaOAMAnuBxhAB9m78WJr5NkYAsyqKvf9Tz8OIpHEj/c8ANqYoO p727tzOTDJPCssxhdcbqo97WIUNZf2O7AM7MNFhcnZdYVi2gLmNNvK/EdHqMOydDAksPCW 8bFbjiwBdhzbW0LwAjLWqrbdhCuX91w= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-520-5OfbqIMSNnOGYKPR4uXWFg-1; Fri, 15 Jan 2021 12:09:19 -0500 X-MC-Unique: 5OfbqIMSNnOGYKPR4uXWFg-1 Received: by mail-qk1-f198.google.com with SMTP id s66so8605057qkh.10 for ; Fri, 15 Jan 2021 09:09:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PCE2jOXT0VlYi8yeqH5i2c+Kk2ht8PluAgOmKW/+jmU=; b=qEVPgAVanV65tH8gYB/HLeu/YnwfEzLOqXztnYY8kmLsQNa/U6ITPAEY2GD2pHkhPh e9FV+ha0JH8Os8A/K/W7k9atWQpkU7xtwnBMrd1KzEBWLfuc5o7RtPMzh3pns2otc5AO CgnHGmpkyHXJp5dyRUoi6v9VovFSM03vgwTaS/8MK+Y48WbSHOhnHlK/lLYgM1rib23X qNRPH6owPS9fNiBoXAJ4TAbDxj7V8UdpXmw6Dy+nr1/CUZkg42P4MBx0EmnLxBbylEbI 8RlUpFFuE5mIv5eU/xEC6IsJR+hfb8INhm7eCGlo5P66B9gVvJTJp4Ema9Yb2bEUTOlE 7UkA== X-Gm-Message-State: AOAM530AoXDxHkpePL3t5CfPYyUqI5htfuCgnVZ7zgAHGfRVSJMV7HM9 Py/sMKxPjbOtqqnkOKcp3UamLdD6VGYEg4OQ6c56Fo8vkQ+GdsPrKycNqbLV3KQouqp7AuT8S/I pwSIKRfhPy+Q= X-Received: by 2002:a0c:b21e:: with SMTP id x30mr13021645qvd.21.1610730559116; Fri, 15 Jan 2021 09:09:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJySkGiY3Z/8br+xmbJLSbFkxSFlEGX46L/q0MAxVvLzmhfZ9gxy0ZD2X+oBqYSHUsZRO+Ix2w== X-Received: by 2002:a0c:b21e:: with SMTP id x30mr13021616qvd.21.1610730558892; Fri, 15 Jan 2021 09:09:18 -0800 (PST) Received: from localhost.localdomain ([142.126.83.202]) by smtp.gmail.com with ESMTPSA id d123sm5187840qke.95.2021.01.15.09.09.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jan 2021 09:09:18 -0800 (PST) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Mike Rapoport , Mike Kravetz , peterx@redhat.com, Jerome Glisse , "Kirill A . Shutemov" , Hugh Dickins , Axel Rasmussen , Matthew Wilcox , Andrew Morton , Andrea Arcangeli , Nadav Amit Subject: [PATCH RFC 05/30] mm: Clear vmf->pte after pte_unmap_same() returns Date: Fri, 15 Jan 2021 12:08:42 -0500 Message-Id: <20210115170907.24498-6-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210115170907.24498-1-peterx@redhat.com> References: <20210115170907.24498-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="US-ASCII" 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. pte_unmap_same() will be used in other places in follow up patches, so th= at vmf->pte will not always be re-written. This patch enables us to call functions like finish_fault() because that'll conditionally unmap the pte= by checking vmf->pte first. Or, alloc_set_pte() will make sure to allocate = a new pte even after calling pte_unmap_same(). Since we'll need to modify vmf->pte, directly pass in vmf into pte_unmap_= same() and then we can also avoid the long parameter list. Signed-off-by: Peter Xu --- mm/memory.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index d6d2873368e1..5ab3106cdd35 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -2559,19 +2559,20 @@ 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); + /* After unmap of pte, the pointer is invalid now - clear it. */ + vmf->pte =3D NULL; return same; } =20 @@ -3251,7 +3252,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.26.2