From patchwork Thu Aug 22 07:13:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13772822 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 B3ACDC531DF for ; Thu, 22 Aug 2024 07:14:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0E0966B02AB; Thu, 22 Aug 2024 03:14:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 069A78000C; Thu, 22 Aug 2024 03:14:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DB1CA80009; Thu, 22 Aug 2024 03:14:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id B14756B02AB for ; Thu, 22 Aug 2024 03:14:03 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 57C10A7F0A for ; Thu, 22 Aug 2024 07:14:03 +0000 (UTC) X-FDA: 82479017166.04.C3BE141 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by imf20.hostedemail.com (Postfix) with ESMTP id 74CD81C001B for ; Thu, 22 Aug 2024 07:14:01 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=deDHovkz; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf20.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.171 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724310776; a=rsa-sha256; cv=none; b=v0++XOofGQuDIa3AAci/Efq6M9o/jzDBNLlxn80G5RCfcR9nB9BvDiff6ugKqAGshYHaiK jKaR1ijvOIBMDtagYpx8eeRuK0I4ECf3jkkIcx62lFlUeSfr7lpI5PUWrx0eugWAbUOKdT nMqChobYsvv+RlCRFTRG3SPcQK3HESg= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=deDHovkz; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf20.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.171 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724310776; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=d/m1IXPfk7xvDU+Qn41r4NiqBFnWc/gEWMU/opSilGI=; b=Nsvu+TJhKH2gt8jRmL6CQUvitOnSeq5rjeZrY2LOlXPdxeTYTFlnpKL84VOWGGptIqvYLK o6hovz6PDvMO1CnZvz/6IqF4WlYPNqZvq9Ty6UcmEpPq+qxXAdHJDiDZIU86z2U41SzcOZ cgPx+H6DHxMXzVVchIOMX1QtNdp7Lco= Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-714187df604so1006291b3a.1 for ; Thu, 22 Aug 2024 00:14:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1724310840; x=1724915640; darn=kvack.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=d/m1IXPfk7xvDU+Qn41r4NiqBFnWc/gEWMU/opSilGI=; b=deDHovkzQGZGhdiJkun0B8NMbSOZ+d9G1oxDR4gDjuU/2ilfB563I48VwPxV3WLkN5 Or3b+WSTpmA4I543zdOwzgzbgFuFqzaiBBi4BDiye5zqFznoPz3/++S9RMOe7QPpowXc t1IvRqOw0WLlZvHArQ+XUW44HB1iKka9z3Je4WFVcIQfFOewwHdD9epcemxvN7zqLv9m yiuuyT4wmU5n2KnTPy34D3Vede5r9xLbbQOfZpstswxbGwK00u2KuSLzbY1HqjUnosxM gxPQsQLi6honPTYovg1HL0wJPl/TuUtXt5RBDf9x5q1uiSpznzUP/uw5yJtCOr633lud 9I9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724310840; x=1724915640; 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=d/m1IXPfk7xvDU+Qn41r4NiqBFnWc/gEWMU/opSilGI=; b=Iz8i8KgOdGg4iLWfd9ESVlMysOZUaRSJYY1wUDsBzhabOv7SYHQjkeQ56QD6eqQc7K eaB9tVnd5iGa0duyqK8a7VJohZZVMh6E4THn88eS/PLXBdSwGAkRxtkhyKk2MXVpH4pU 165axnOStwFpSDPShViOFqKk/ljty5BHHIXeSkNZO61zj74MLFuSDwa6G07TPod24Jow 9xaKLa4dwMJqRtWsWaRd+/g2lQemiyEGCGoFp/m+sFoIgpHly834xl6T38+Y2vK4Q5oO zyDMFykYiduyuUL+UcQFJOdTGJ9Uvq13o/ui3tpZ16MK9yBUPqwTNQXz21I9/VudbdIS Gzsg== X-Forwarded-Encrypted: i=1; AJvYcCW9gamSgvw8HTOqQmiAHs42JRHJF1OAR6vbXkdO9zoXyweVnZJEZJMq2DL0gDDRssAkFeY4CfDQmQ==@kvack.org X-Gm-Message-State: AOJu0Yw8rS5rFNd/i0A4gFWNnfGBuKImnP7zvSJ3zyzD0Cx+GBQ5AYF2 gMOI+cuY/WoZB9ZAZs2cfconplGIjtTvYdc8dAnP2REW8WR0NlhM1Ey4D/GEDNM= X-Google-Smtp-Source: AGHT+IEhsa9RMy8FC6eeC7Dc/qzW9nWoiqPGY6DtNfgP/dDTOo2T0oKgHsMPC17UGp2n78kSJG5uNg== X-Received: by 2002:a05:6a20:6a2a:b0:1c4:9c08:5df3 with SMTP id adf61e73a8af0-1cae51cf01cmr3205085637.7.1724310840022; Thu, 22 Aug 2024 00:14:00 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([240e:473:c90:f96:d029:ea8a:4e6d:d272]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7cd9ac994a3sm695095a12.16.2024.08.22.00.13.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2024 00:13:59 -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 v2 02/14] arm: adjust_pte() use pte_offset_map_rw_nolock() Date: Thu, 22 Aug 2024 15:13:17 +0800 Message-Id: <7915acf5887e7bf0c5cc71ff30ad2fe8447d005d.1724310149.git.zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 74CD81C001B X-Stat-Signature: 9ss1oeeu644aredzpdhatoisfwxy5yfy X-Rspam-User: X-HE-Tag: 1724310841-358690 X-HE-Meta: U2FsdGVkX1/iHuFZKFhUB9ESKFM7EApR9AgWMGMsQID3q6ow+op3hGLRURa6mvmUCZjQnq9u2dZUaYPbT046S5r1IqzcGCLRnYY7lHhvD9Ggx8cF+S+KUYXlw2BktCk95HyNuAqm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WYbzVyrzhIzXcmMrGT8YgH39FyBatchfo2L1EMfU6DKOeR4+yGTzByr0MLvidWG7HF2OTZ8tXvVf/WjsZlXSAPmGpkKChk1xNkvCrnyLGP9fyUFPQZ9HgDTTwqEJbGg3saM/6SiHyor3dAZn2VSjj3OaJ8FHptz2zMPSNXz4cRy4nIu02xNyIHYn4n4giC5M9GmhYrULAMGATvM8WCbsdZ1Aq 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: List-Subscribe: List-Unsubscribe: In do_adjust_pte(), we may modify the pte entry. At this time, the write lock of mmap_lock is not held, and the pte_same() check is not performed after the PTL held. 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);