From patchwork Wed Sep 8 16:36:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12481525 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 E4BB8C433F5 for ; Wed, 8 Sep 2021 16:36:27 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8263261139 for ; Wed, 8 Sep 2021 16:36:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 8263261139 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 2E5A86B006C; Wed, 8 Sep 2021 12:36:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 26E886B0072; Wed, 8 Sep 2021 12:36:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 10F836B0073; Wed, 8 Sep 2021 12:36:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0124.hostedemail.com [216.40.44.124]) by kanga.kvack.org (Postfix) with ESMTP id 02C0D6B006C for ; Wed, 8 Sep 2021 12:36:27 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id BC6362FD88 for ; Wed, 8 Sep 2021 16:36:26 +0000 (UTC) X-FDA: 78564959172.02.8B39569 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf27.hostedemail.com (Postfix) with ESMTP id 6CF6270000A0 for ; Wed, 8 Sep 2021 16:36:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631118985; 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=VOug+yt+rtSnFCpb+o2ehs/JosfLWaw2JI2Efn6LKBEh5E+k5RjvEdfS8T7OjvHTYlLZg9 XLFFtYvwInz9+xrmTKrAmv0DJP4ogtrgYbbchpI5GICGiHtf+VmnRen4vFleiKKBDO/wnA tzly3PHmkqbNflwyO7L+JS7gW8XRu7Q= Received: from mail-il1-f199.google.com (mail-il1-f199.google.com [209.85.166.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-175-EW6hI-rANzSyBKF_ss5Jvg-1; Wed, 08 Sep 2021 12:36:22 -0400 X-MC-Unique: EW6hI-rANzSyBKF_ss5Jvg-1 Received: by mail-il1-f199.google.com with SMTP id r6-20020a92c506000000b002246015b2a4so2090720ilg.21 for ; Wed, 08 Sep 2021 09:36:22 -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=jlWmRKk5CdgJT10CU03ALN3ccT13na2rxsTWIxGjRsP6crpaJ08/FyY8D9kei4MOgx 9Rd0nWunZgf8AP89tsMq00mibUPUKUUQ+pMGRaZGaBPZ7+UdPVQU3LcNq4XdmtH0w5W8 PJ/7VKIMEQOBzdC8IJ5Ab/aFdDZUMCz6gyctd1e4DcM4ykTWdMLSBEIX7/DzQaczDEp9 AqaU1iTdgEGqUyMCN6GPRoafXChy7PcxhrJp1OjMh5gjBt7nvyqwQlGvhCoZqgOcjPOs ogw0trxivRPDQLvoHeH6+Z1LzobXQAYwEHgocuZPtRmcsSlA69o4kJz8XyzgJ7gEHLnK u9WQ== X-Gm-Message-State: AOAM530L0m9F07YibThbAJuNz/Zeb3rkSK00rWmHVVLpRLDvu9RumSBi 2uVG1YBdt+hXFXoxK0em7m1TbKvLOe9X6Fv4AMjcrNUZNqtq/EuhQ9q7j898nrWM65uc8RP9jsR eyfKCQ0m5srk= X-Received: by 2002:a05:6602:d9:: with SMTP id z25mr645545ioe.154.1631118981961; Wed, 08 Sep 2021 09:36:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1EbGLCnuAcfZACCBnyvgCaW1SFMtQKrjHJRqiyYZqaaZQiJRFzEufdRaFsqV34fbIanuG2w== X-Received: by 2002:a05:6602:d9:: with SMTP id z25mr645522ioe.154.1631118981774; Wed, 08 Sep 2021 09:36:21 -0700 (PDT) Received: from t490s.phub.net.cable.rogers.com ([2607:fea8:56a3:500::ad7f]) by smtp.gmail.com with ESMTPSA id n37sm1268406ioz.5.2021.09.08.09.36.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 09:36:21 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, Andrew Morton , Hugh Dickins , linux-mm@kvack.org Cc: Miaohe Lin , David Hildenbrand , Andrea Arcangeli , Yang Shi , Alistair Popple , Matthew Wilcox , "Kirill A . Shutemov" , Jerome Glisse , peterx@redhat.com, Liam Howlett , Mike Rapoport Subject: [PATCH v3 2/5] mm: Clear vmf->pte after pte_unmap_same() returns Date: Wed, 8 Sep 2021 12:36:19 -0400 Message-Id: <20210908163619.214901-1-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908163516.214441-1-peterx@redhat.com> References: <20210908163516.214441-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 6CF6270000A0 X-Stat-Signature: 9eg71m4jojauissanif71m9ijg1odhya Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=VOug+yt+; spf=none (imf27.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-HE-Tag: 1631118986-713958 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 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);