From patchwork Wed Sep 4 08:40:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13790185 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BAF50CD37B6 for ; Wed, 4 Sep 2024 09:08:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=H/kyF9mn9oESktxWYdr3s8d2VJ5iyYEZZY3E5BXrvv8=; b=UsfSUldWwnJu9UkzyvcZ4pZ4ln dOnoAyft17fhIa5mcKS3ceQ8IA7vDRh5jHsMkq9chQM10gp68PB41zbGwnoBEaQ1ct7c9jnv9/BEH Q5umM7M8FAGI3nq+59ed9QZZExKr8B8JOnm0A62YrWVCm98dCEczHleqQZBIT0vV/Yu3fTktzzTKq J/62agxeB8oi4psN1FUwX1FcHYrrKCAOP8DQNVBUL6OGpEDcNVdO5ZE6/YDytSfo1Fy2v/Z9X/UIG Lccxel0bDsMx1kh34QdRR6A0vLRzSKZC0hKeqDKhw7/7ZKICpXmF2l9HwGzdfjSe+81dQo6FnqGl6 8HDpLqtQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sllzf-00000003bAb-0AQb; Wed, 04 Sep 2024 09:08:03 +0000 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sllZR-00000003SyJ-2FJN for linux-arm-kernel@lists.infradead.org; Wed, 04 Sep 2024 08:40:59 +0000 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-2053f6b8201so31852285ad.2 for ; Wed, 04 Sep 2024 01:40:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1725439256; x=1726044056; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=H/kyF9mn9oESktxWYdr3s8d2VJ5iyYEZZY3E5BXrvv8=; b=Ire2maEjNqfS3vpM1R5Ly0ZjL6J19buFsGqBrCFmEYUfvc3gtWxcDaM+AnUKk+Vfah 30IQvFIYBC6ziEmbNOwuSjv3IVbcNYmxJKeuL7ZqWfZfILP3/Xztw1+vu4V46q8BNT8R 1KfTVKz9e4QfloJntV3gqMuF87Z9RDBAG1jm0PcHWI7NxxCeteLLLT5d0oNAwBuE7Xjs qYNFOzlFkVAR9Tpve8XLgbzLoSgCuB5VSZg2c/N6KtLGfruXywmoLM8mElcq/o3w61KB 0uucS0DC+Yo4+fP799ju80KwdGqohDNgTrOTziBauj2jm5Bnq3z95Ai6u46Ve28u3UE7 D5aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725439256; x=1726044056; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=H/kyF9mn9oESktxWYdr3s8d2VJ5iyYEZZY3E5BXrvv8=; b=FCnvSafTBCuPsQdDEopRM4LGpx4FGvg6q97OZLoZFaGgSKzxkB2taxY072gnfE4rDt Mgd92IMXdoXndJb26Nkm4Yg09/lbqwteHJ4NQnjPO7I6OHZE4bS9dcSPzioUm9ml9q9A jhMQIAksPW/AnutUjATfRBP3a18oB4Bmhij2n+B8z9+HQv1BQcYQLAFYlOeTiNlepA0h L/ZZO1w/aiRQUpAWWgMuJB0m9XoWYUlUV9U91XAO94whyzDN+SqCp7zU/kF2Lell9EWW zmLvUdWrx3IkFZ4KvIViAhI9CFbEK9Fvl0CoHDYc6rWnuMtc1nT8fZwN7oqDzkH1uux7 aYUQ== X-Forwarded-Encrypted: i=1; AJvYcCWrWfrcWM7JDGoGjgQsxAWY70ctUoAUSpfhEToBcG8UJFMdrH1JW7JRQmAy9GOwDlrNeW9gVWVEaWLS6ysjYveK@lists.infradead.org X-Gm-Message-State: AOJu0Ywjey2F4mVqUnHNsnSVW4OeNCgQ+FQyX8G5u0QysX7sh9sRfSYn Pi4nXX+ESCP+YyTVUw8HVW1+Zfca1/MeeUznlLxLXVL628s6UiedCvVu8AbHdAs= X-Google-Smtp-Source: AGHT+IEEdhBdCGQBBk6sF5V8bi+PhpxKTNotIZgwSj7kMgQxLZV/04loActQGvyTL5xDqZZl1Kbj6A== X-Received: by 2002:a17:902:f547:b0:206:b618:1d7f with SMTP id d9443c01a7336-206b61824c9mr14802495ad.37.1725439256381; Wed, 04 Sep 2024 01:40:56 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([139.177.225.242]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-206ae95a51csm9414045ad.117.2024.09.04.01.40.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 01:40:56 -0700 (PDT) From: Qi Zheng To: david@redhat.com, hughd@google.com, willy@infradead.org, muchun.song@linux.dev, vbabka@kernel.org, akpm@linux-foundation.org, rppt@kernel.org, vishal.moola@gmail.com, peterx@redhat.com, ryan.roberts@arm.com, christophe.leroy2@cs-soprasteria.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, Qi Zheng Subject: [PATCH v3 02/14] arm: adjust_pte() use pte_offset_map_rw_nolock() Date: Wed, 4 Sep 2024 16:40:10 +0800 Message-Id: <20240904084022.32728-3-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20240904084022.32728-1-zhengqi.arch@bytedance.com> References: <20240904084022.32728-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_014057_692743_FC4E9990 X-CRM114-Status: GOOD ( 12.40 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org In do_adjust_pte(), we may modify the pte entry. The corresponding pmd entry may have been modified concurrently. Therefore, in order to ensure the stability if pmd entry, use pte_offset_map_rw_nolock() to replace pte_offset_map_nolock(), and do pmd_same() check after holding the PTL. Signed-off-by: Qi Zheng Acked-by: David Hildenbrand Reviewed-by: Muchun Song --- arch/arm/mm/fault-armv.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/arm/mm/fault-armv.c b/arch/arm/mm/fault-armv.c index 831793cd6ff94..de6c7d8a2ddfc 100644 --- a/arch/arm/mm/fault-armv.c +++ b/arch/arm/mm/fault-armv.c @@ -94,6 +94,7 @@ static int adjust_pte(struct vm_area_struct *vma, unsigned long address, pud_t *pud; pmd_t *pmd; pte_t *pte; + pmd_t pmdval; int ret; pgd = pgd_offset(vma->vm_mm, address); @@ -112,16 +113,22 @@ static int adjust_pte(struct vm_area_struct *vma, unsigned long address, if (pmd_none_or_clear_bad(pmd)) return 0; +again: /* * This is called while another page table is mapped, so we * must use the nested version. This also means we need to * open-code the spin-locking. */ - pte = pte_offset_map_nolock(vma->vm_mm, pmd, address, &ptl); + pte = pte_offset_map_rw_nolock(vma->vm_mm, pmd, address, &pmdval, &ptl); if (!pte) return 0; do_pte_lock(ptl); + if (unlikely(!pmd_same(pmdval, pmdp_get_lockless(pmd)))) { + do_pte_unlock(ptl); + pte_unmap(pte); + goto again; + } ret = do_adjust_pte(vma, address, pfn, pte);