From patchwork Tue Apr 5 01:48:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12800959 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 F02FBC433F5 for ; Tue, 5 Apr 2022 01:49:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DDA686B0073; Mon, 4 Apr 2022 21:48:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D89806B0075; Mon, 4 Apr 2022 21:48:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C045D6B0078; Mon, 4 Apr 2022 21:48:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id B1B6A6B0073 for ; Mon, 4 Apr 2022 21:48:52 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 8A1C523861 for ; Tue, 5 Apr 2022 01:48:42 +0000 (UTC) X-FDA: 79321141284.15.A95C836 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf01.hostedemail.com (Postfix) with ESMTP id 0F96E40036 for ; Tue, 5 Apr 2022 01:48:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649123320; 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=sVIJ8cJ4ZYWLy9njZqjP9dBoADUUbduMAUK9CqZAoa8=; b=b90Rgh8dHIXO22+Vrad1/EkM+DtOL72P/a5YIiBcJQ0IeQUHbYLCj7eEja2qNkc1bag5iJ DQ2XvXB4YUttO9/VIiVqRrje/pkedUnGM8u3YL7ERFZQ6BSwMqitH3vcZWYSrGzesbODX6 X3VEVmkXE0oyvIiapnuztb26+etW4nY= Received: from mail-io1-f69.google.com (mail-io1-f69.google.com [209.85.166.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-307-6WqGl_DNOa60UthPi97f1A-1; Mon, 04 Apr 2022 21:48:39 -0400 X-MC-Unique: 6WqGl_DNOa60UthPi97f1A-1 Received: by mail-io1-f69.google.com with SMTP id u18-20020a5d8712000000b0064c7a7c497aso7416268iom.18 for ; Mon, 04 Apr 2022 18:48:39 -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=sVIJ8cJ4ZYWLy9njZqjP9dBoADUUbduMAUK9CqZAoa8=; b=TgsoH093Xqqcq4s4lAHQIfqhsULC64wFeu2C6B4xPraWFD+wCBScEPA7AcRi2vSm0b fiGBSv399sr2x45jI2TBDAhhNTGUAIdm1g49gqal986hPMFMRLSEolHZRXn7vtsMolXt c0bSaMlfT8Twq6efPWed0aCMwcL9p02v3ZgdH2NSe+r0lqG9Zux9RJT0EDaDHP0D4I4K tX1O9uBTI19P5C7WiR+Zn+wMeum2NHPQlCngzikMcp67GbWaJWapTXaN8sYGFuvun4aQ tGrO1Wralnsnz+PwROC6ghWKSDtWVzJJSVu3qFinY2IgzQAzCKAJg38gt8o/G7sp9v/m TvMA== X-Gm-Message-State: AOAM533ibvVGS4OkHxeuAhqF+SeWox1UK+IG8k8JlibFChWcCgmXpxBK vlVjos7OwxKWABk9HFuXGgAjjC0aQufksV1lX5rVfvHbWE7J0a/O5kXTQsN3lpru2yox1LKCQ7Z Gf59/8oblk5A= X-Received: by 2002:a92:cc41:0:b0:2ca:317d:1545 with SMTP id t1-20020a92cc41000000b002ca317d1545mr610363ilq.97.1649123318850; Mon, 04 Apr 2022 18:48:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw4r+oclsvcEsUiRUe9DMRABSCkkiRtx/NYkAy387pbnwUItvkV/gFFJ6K8jTgQhR+UEusSug== X-Received: by 2002:a92:cc41:0:b0:2ca:317d:1545 with SMTP id t1-20020a92cc41000000b002ca317d1545mr610343ilq.97.1649123318645; Mon, 04 Apr 2022 18:48:38 -0700 (PDT) Received: from localhost.localdomain (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id s5-20020a056602168500b0064c82210ce4sm7650542iow.13.2022.04.04.18.48.37 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 04 Apr 2022 18:48:38 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Mike Kravetz , Nadav Amit , Matthew Wilcox , Mike Rapoport , David Hildenbrand , Hugh Dickins , Jerome Glisse , "Kirill A . Shutemov" , Andrea Arcangeli , Andrew Morton , Axel Rasmussen , Alistair Popple , peterx@redhat.com Subject: [PATCH v8 03/23] mm: Check against orig_pte for finish_fault() Date: Mon, 4 Apr 2022 21:48:36 -0400 Message-Id: <20220405014836.14077-1-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220405014646.13522-1-peterx@redhat.com> References: <20220405014646.13522-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: j67j8z6rwjgnmsbaagn3gw67wrqof6ht Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=b90Rgh8d; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf01.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=peterx@redhat.com X-Rspamd-Queue-Id: 0F96E40036 X-HE-Tag: 1649123320-588617 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 Reviewed-by: Alistair Popple Reported-by: Marek Szyprowski Tested-by: Marek Szyprowski --- mm/memory.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mm/memory.c b/mm/memory.c index 3f396241a7db..b1af996b09ca 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4241,7 +4241,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; @@ -4709,6 +4709,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