From patchwork Thu Sep 2 20:17:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12472437 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 F00A0C4332F for ; Thu, 2 Sep 2021 20:17:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A55F96112F for ; Thu, 2 Sep 2021 20:17:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A55F96112F 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 3BA626B0072; Thu, 2 Sep 2021 16:17:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 36A8B8D0002; Thu, 2 Sep 2021 16:17:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 147F48D0001; Thu, 2 Sep 2021 16:17:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0164.hostedemail.com [216.40.44.164]) by kanga.kvack.org (Postfix) with ESMTP id 01E446B0072 for ; Thu, 2 Sep 2021 16:17:32 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id BC35F18206D51 for ; Thu, 2 Sep 2021 20:17:31 +0000 (UTC) X-FDA: 78543743502.18.7BB65E0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf13.hostedemail.com (Postfix) with ESMTP id 6353B1025AAA for ; Thu, 2 Sep 2021 20:17:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630613850; 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=cdgHKq2iasOqwEaJuLz/zWtoLSwDiCtJqQzcku8x6HU=; b=TwPQ00gODxU40fRAGWPm3usf2penegvakzc7y4mpHYoEOI+L92/RehVinwo+0vBqFzR99g h/sXM0WjOacUEuZxxC2wbkPLgilwT96cESkY8LUI7S5Mfw/jfxogijwUAefUT/UYgrM7pI iOFSoFszouaQJaM5r4F8y2uPDmfKbjk= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-532-4Xmd3b0jPk6JXukw1y3Zcw-1; Thu, 02 Sep 2021 16:17:27 -0400 X-MC-Unique: 4Xmd3b0jPk6JXukw1y3Zcw-1 Received: by mail-qv1-f69.google.com with SMTP id l12-20020a0cc20c000000b0037766e5daaeso3435012qvh.10 for ; Thu, 02 Sep 2021 13:17:27 -0700 (PDT) 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=cdgHKq2iasOqwEaJuLz/zWtoLSwDiCtJqQzcku8x6HU=; b=bF/eMfy2OSapZY5i7qS6MUfLkmTE/AcoI5g+qqYguqOpXWWTzNJECWGiPCab4q5K9f MWMKf2LPuNYgrbOpvhq0exDNdNik0LMoJ8Xa6Q3di/E66Ur0eSuiksDQfs8O1TniLT3X psl9MRngwewZ+C51RIsi1ORHPvUbNMK0qAgnfv3qJtDc62VOp1xPz+6tjkOELZa3nRt1 /OT4DcBtBTFnNGFC6UPjyF+tEYPsxnWIAx+RLt1NB+ji+cBZtdkc+cvDBF+2hOqy4Yoe c5F+eVzS9c/W+nibCB56sDuE+j6Oswf/m/NZfqQ+M93xb9vnsPKgpNPvQKurNPxuyU7P v0nw== X-Gm-Message-State: AOAM530YfUFeTYT+YsO08ZnErhF38BPNoVM+T8nnX7AXOHfesYeseEek N9SbKTajDF5ObgciOiyZgP7jyB/SkPzIl3dYn67seFFVC00scz/JXyMld7TTFqFlQQ8qJXiE6yf khnJ58kAdVvI= X-Received: by 2002:ae9:dd43:: with SMTP id r64mr5073148qkf.225.1630613847435; Thu, 02 Sep 2021 13:17:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy538vhBDKUaB7nJWBgP4Dij+Fv0SB/UrIvpqCgIyHMHGnI8luhqctobjoYIX8mKB8YeK+nsw== X-Received: by 2002:ae9:dd43:: with SMTP id r64mr5073117qkf.225.1630613847180; Thu, 02 Sep 2021 13:17:27 -0700 (PDT) Received: from t490s.redhat.com ([2607:fea8:56a3:500::ad7f]) by smtp.gmail.com with ESMTPSA id m8sm2219962qkk.130.2021.09.02.13.17.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 13:17:26 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, Andrew Morton , Hugh Dickins , linux-mm@kvack.org Cc: Andrea Arcangeli , Yang Shi , Matthew Wilcox , peterx@redhat.com, Jerome Glisse , Mike Rapoport , "Kirill A . Shutemov" , Miaohe Lin , David Hildenbrand , Alistair Popple Subject: [PATCH v2 2/5] mm: Clear vmf->pte after pte_unmap_same() returns Date: Thu, 2 Sep 2021 16:17:18 -0400 Message-Id: <20210902201721.52796-3-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210902201721.52796-1-peterx@redhat.com> References: <20210902201721.52796-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TwPQ00gO; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf13.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=peterx@redhat.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 6353B1025AAA X-Stat-Signature: zen4tr91usc1s6btnj348gf7o83jonp8 X-HE-Tag: 1630613851-613337 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_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 Signed-off-by: Peter Xu Reviewed-by: Liam R. Howlett --- 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);