Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp711774pxb; Wed, 15 Sep 2021 11:17:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxyLMdM3+teQ2pjEpy6Dq9c50cJ5T7BdAo2rbI8s2/EH4PVhpHX48aIVnpEZrshpY1s45No X-Received: by 2002:a17:907:16ab:: with SMTP id hc43mr1420444ejc.195.1631729848825; Wed, 15 Sep 2021 11:17:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631729848; cv=none; d=google.com; s=arc-20160816; b=immikgduONMug6pmO7dU7hAjiCl/GSo8bAlTSALHcFGlNcRfZqfRLbyTlKrpRb39CW fKWyNLhAdlBvaZ6z/OcXzQVCGP5/23onKfnGbhK6YJ9I+lvwxc3Hg6GCfeW8I9S1pHQG JHSsDsDHIhJwfMpGH0u+5D/ciUPYFP/uTt+fIVUw2zis6qUrryfQZnihe6czaT6EayR7 ZqqHWUJpziVUI3zdV4IBOXmm6A2YHUxYW2SwWzftEFJY2a64iZUH+ZyU71AOa3sgtyNE vv8fPCUsvwMw/5j1Xh13dkLS4kfRly19//6X4h3CBtTB2BzmrJaHtV6VBEhwhJ8sEbBQ SB/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=yCBcgdQfSQO0vdlLaUvPYqHDlVPUHtkRpfsoC2DOf1s=; b=Uj3Al9Fa8GGw4BiVJ0lr9dTx2vHS7f+alTTjTUOi2542vNFQALEXJA7Hu/px9hA5y0 ClIXKH8LjkLuUiFvt2L8GU6wBOe+63f2cU/4dJhWgRpKCUCAvw8mcVXM6vX79hgFcxuX PwU454ERw+X7/YjCrikWfssCBqGmYuuxdiaefKCzjwEATCOvCPmMdvW5EQ4y5iln6S5g vIQNtZ4u7R8SIsThJEXM5zKA2ImNQTttRY1hHyRcWTXYCpado1QseVhiFGBrozGXyaxf d2Pk31zm2C/Ba7QB6m1lWy7fMNxm42Sq8hi5DSsdYs4l35OcKryHHqG5x8TF/e4Auvhb TszA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=jVdUfGfo; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gt40si716384ejc.9.2021.09.15.11.17.03; Wed, 15 Sep 2021 11:17:28 -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=@redhat.com header.s=mimecast20190719 header.b=jVdUfGfo; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231226AbhIOSRA (ORCPT + 99 others); Wed, 15 Sep 2021 14:17:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:60788 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229738AbhIOSQ5 (ORCPT ); Wed, 15 Sep 2021 14:16:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631729737; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yCBcgdQfSQO0vdlLaUvPYqHDlVPUHtkRpfsoC2DOf1s=; b=jVdUfGfoaK69uuH66J18ya2Q7Gb2TkGmwajOXQHIUzNKzqwDOx1sQWxgZPpbCKm9/5OQ3T f3rSGAZDMc/fDvUE4mwO/p7VFnahaGlPlZyIz+a7QCebwe9KeoEibdaS7/Wm1STa0zMGZq JiBpby7kktu6ZOsCiKk8/3rYNZSMu04= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-323-BNo0JLnLO4inNm8xuOMwCw-1; Wed, 15 Sep 2021 14:15:36 -0400 X-MC-Unique: BNo0JLnLO4inNm8xuOMwCw-1 Received: by mail-qk1-f199.google.com with SMTP id w2-20020a3794020000b02903b54f40b442so6234653qkd.0 for ; Wed, 15 Sep 2021 11:15:36 -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=L6zQ3UBNrZUIvXq33f/gHFP3aAmvTPrq9ePEtyZqxUZPTmcoqAtk6u1kECtMJJ2y+S M8+smvvrrF94K8wZdFwIhV28sY7xXvjnzkC9eeCgMce4F1bTM8ZRdVCcDjTcT0ZE4MYb SIwnAM6fvnve10p6kBYNWVTtLzh/HZJNiuOmUqrMjYBnclfmwJlfugaficXyi4W6MkeV SIPHkQuJgUuSTnDPhqsiLevpzd3kdixi7JQ61XZY+CGj+DBM+xdlUWIajbkD6Go4ZUpy 2IVp09YQ0dRn8CxJvqA6SitpMA2OJLNJTf8I/TCJwYC8nhMueW5xtYa3xpE4OEa+ftqb KbLA== X-Gm-Message-State: AOAM531Y4I+LVMgvqjnrpUyIvoPb4sqaoiUzKXeGjm7UqXskQ3Qcb6Xx xQuMJi/kJVWIElWjKW9yof2/pQN7tryn2AbiBqXniM47gX2K3dXoxafmnzS1AZFTVdLfYlKUsM9 TLoM5nJmb6V930W3cV7lmGLUOJbk4uQNrB3XVZg0X3AQo/VmRq9+VkAPyIhHYx4XvuTwELvDJpw == X-Received: by 2002:ae9:e858:: with SMTP id a85mr1259147qkg.97.1631729735589; Wed, 15 Sep 2021 11:15:35 -0700 (PDT) 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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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