From patchwork Fri Mar 4 05:16:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12768458 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44A7CC433F5 for ; Fri, 4 Mar 2022 05:17:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C8CAC8D0006; Fri, 4 Mar 2022 00:17:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C3BDD8D0001; Fri, 4 Mar 2022 00:17:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B2A988D0006; Fri, 4 Mar 2022 00:17:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id A50888D0001 for ; Fri, 4 Mar 2022 00:17:50 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6FA4E22762 for ; Fri, 4 Mar 2022 05:17:50 +0000 (UTC) X-FDA: 79205546700.02.B8CA9BC Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf15.hostedemail.com (Postfix) with ESMTP id 9DA6CA000C for ; Fri, 4 Mar 2022 05:17:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646371069; 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=DWHI+KLiCdBad7t4Fcw0RAEljy7M5LeKI3evjgamGnQ=; b=EfC1GuAUFfEESPtX9JLqTttVWH1i2A0/a8Yw8Ftes9rxieTSapTY2eP4RCRMDevOdylpBU y5BgAXlbu+TmdVdr+DjY9h+TuVaUyiaudCS60lahl7s/2P/v+yte+U7vfJVwhxYQ8EH3IH h3HDYT/eUawzz42osnf/ZyrLO9mPYuQ= Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-110-ej5fZQypNPuNAc_UGJFlWg-1; Fri, 04 Mar 2022 00:17:48 -0500 X-MC-Unique: ej5fZQypNPuNAc_UGJFlWg-1 Received: by mail-pl1-f199.google.com with SMTP id z10-20020a170902708a00b0014fc3888923so4089727plk.22 for ; Thu, 03 Mar 2022 21:17:48 -0800 (PST) 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=DWHI+KLiCdBad7t4Fcw0RAEljy7M5LeKI3evjgamGnQ=; b=PU+w7M+WuiGvTgYZ+7ROLqvfdFg3WR1JWtLvN8ELU9phQ7HKRo1ew2BMaR4X0Rq/FL ZYFTAqvuyYQcutLZp8YSB/1ooqUKnGoMLLtXAgbWqO/+m7vhegXrcwv/31rJuwQjoOIz qbHf5RhxAUe1D2zEULggIDESCfoQkFVfUwAjD6Ich+CmequupS1II/GptMAuqPkElZ1O 2oiT5KGyXvQb4TXe05ng0atJXGMyRihP7I1lWvsHrh7kaUFd5kfjTwBQQLFW6cNUMBFJ PpiWUh4a3OMSDEL6zir2iQY+lyD/Ys4d4EZ1g88Y6BrHry3938ypZgROy/m4QYcwI6w5 QvgQ== X-Gm-Message-State: AOAM531PmKW18Nu6MDyy7U75ukQgwnXQRN/pbm91eUGHolpaTGkC4hdo g4lbn20TCp7c+OXjA8CU1ZLwEv80jFCo8sQcBFEHGVplRqZNsqcnkiBeGq11z2iGs9eid9HOqon xfk25HcYatSGNWUug14Bos2/sMMbcc9zlR4R0JdA0nRFsRUdsajdWzUhXYqSY X-Received: by 2002:a17:902:d894:b0:151:64c6:273 with SMTP id b20-20020a170902d89400b0015164c60273mr24307322plz.150.1646371067215; Thu, 03 Mar 2022 21:17:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJwBDtDn1Z3wbdPzigbaBlDKAgZd/ChJa3km/enVI+LZTN2c4X2t5bAMomnNrL0k2Ir186+95Q== X-Received: by 2002:a17:902:d894:b0:151:64c6:273 with SMTP id b20-20020a170902d89400b0015164c60273mr24307281plz.150.1646371066620; Thu, 03 Mar 2022 21:17:46 -0800 (PST) Received: from localhost.localdomain ([94.177.118.59]) by smtp.gmail.com with ESMTPSA id p16-20020a056a000b5000b004f669806cd9sm4323865pfo.87.2022.03.03.21.17.39 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 03 Mar 2022 21:17:46 -0800 (PST) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: peterx@redhat.com, Nadav Amit , Hugh Dickins , David Hildenbrand , Axel Rasmussen , Matthew Wilcox , Alistair Popple , Mike Rapoport , Andrew Morton , Jerome Glisse , Mike Kravetz , "Kirill A . Shutemov" , Andrea Arcangeli Subject: [PATCH v7 03/23] mm: Check against orig_pte for finish_fault() Date: Fri, 4 Mar 2022 13:16:48 +0800 Message-Id: <20220304051708.86193-4-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220304051708.86193-1-peterx@redhat.com> References: <20220304051708.86193-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 9DA6CA000C X-Stat-Signature: xcww5b75mdz7h95ffqzphhr4szgd58gp Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=EfC1GuAU; spf=none (imf15.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-HE-Tag: 1646371069-651862 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: We used to check against none pte in finish_fault(), with the assumption that the orig_pte is always none pte. This change prepares us to be able to call do_fault() on !none ptes. For example, we should allow that to happen for pte marker so that we can restore information out of the pte markers. Let's change the "pte_none" check into detecting changes since we fetched orig_pte. One trivial thing to take care of here is, when pmd==NULL for the pgtable we may not initialize orig_pte at all in handle_pte_fault(). By default orig_pte will be all zeros however the problem is not all architectures are using all-zeros for a none pte. pte_clear() will be the right thing to use here so that we'll always have a valid orig_pte value for the whole handle_pte_fault() call. Signed-off-by: Peter Xu --- mm/memory.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mm/memory.c b/mm/memory.c index 22d24ea7b87d..cdd0d108d3ee 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4135,7 +4135,7 @@ vm_fault_t finish_fault(struct vm_fault *vmf) vmf->address, &vmf->ptl); ret = 0; /* Re-check under ptl */ - if (likely(pte_none(*vmf->pte))) + if (likely(pte_same(*vmf->pte, vmf->orig_pte))) do_set_pte(vmf, page, vmf->address); else ret = VM_FAULT_NOPAGE; @@ -4600,6 +4600,13 @@ static vm_fault_t handle_pte_fault(struct vm_fault *vmf) * concurrent faults and from rmap lookups. */ vmf->pte = NULL; + /* + * Always initialize orig_pte. This matches with below + * code to have orig_pte to be the none pte if pte==NULL. + * This makes the rest code to be always safe to reference + * it, e.g. in finish_fault() we'll detect pte changes. + */ + pte_clear(vmf->vma->vm_mm, vmf->address, &vmf->orig_pte); } else { /* * If a huge pmd materialized under us just retry later. Use