Message ID | 20240904084022.32728-15-zhengqi.arch@bytedance.com (mailing list archive) |
---|---|
State | New |
Headers | show
Return-Path: <owner-linux-mm@kvack.org> 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 40876CA0ED3 for <linux-mm@archiver.kernel.org>; Wed, 4 Sep 2024 08:42:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BCF3E8D023F; Wed, 4 Sep 2024 04:42:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B57048D0239; Wed, 4 Sep 2024 04:42:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9833C8D023F; Wed, 4 Sep 2024 04:42:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 72EBE8D0239 for <linux-mm@kvack.org>; Wed, 4 Sep 2024 04:42:19 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 3EDE3120E4B for <linux-mm@kvack.org>; Wed, 4 Sep 2024 08:42:19 +0000 (UTC) X-FDA: 82526413998.19.2859515 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by imf15.hostedemail.com (Postfix) with ESMTP id 651A6A0002 for <linux-mm@kvack.org>; Wed, 4 Sep 2024 08:42:17 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="Ke1/djqb"; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf15.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.182 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=1725439230; 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=ylbiZHnndQyBxRrEPbsYoqCd5Ue19pmhRhZr0okk+70=; b=N+SM8ZZrC00b9qrzUVOn+3K3Oi5G34K07sklmT6UR/Kd3m4z3VNVlEaFK0e65A63HzQM1l WKQ78dR9ExU+2vIKVtRjlB1Q0YixSu0Xupl/9JRLUuLs3OEeWZYqQwhhPE/+9fnqtkSaiN bH9RJ+JeFbjPGTjB1hh1KXCRDJxw6qA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725439230; a=rsa-sha256; cv=none; b=E8K0e7iCORrMCHlskQkdRIeinXgLF7kAJVNbE9Etlsy3YqwNbiXvEw9rzRjCmT5DaMpu4Z cjoiGOCsN7upG61SCB0FG5CUYOfhRErmcC7nLdK6EV+jtKgKmLGhz6rFif164uFWRld4MN 7l3NaVo9ZRHMUqAepUVkf2dTH9gRg9E= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="Ke1/djqb"; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf15.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.182 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2053525bd90so32717365ad.0 for <linux-mm@kvack.org>; Wed, 04 Sep 2024 01:42:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1725439336; x=1726044136; 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=ylbiZHnndQyBxRrEPbsYoqCd5Ue19pmhRhZr0okk+70=; b=Ke1/djqbHbl11bwC/WM51pOHXtgtMTcIBMNFMLa9tF2eFgMkWnWbYBmocy835A14kb ZEQSCHd8sq0qaPHehzMZozxz7qVpdKi3jAoA9qUghBpV5rBp0oiLqYv5lVUmi2V2Z/1k CEy3iHkwK+T2CKImFzZmAnckxzFZ+Jid24IwJ396iz8yVj/4lZ2J+oLltV2uhV+sZSiY PicjM35zGdalIr8TyqNl93gUpWoOnnKD5aK54rb89g3JhiAI/7KNn1C17tvhpD0cFXNZ mGaXj21wdSMpAMJiy39SwDfnWBLJtfID/fxRrHf//v1VPGMOTLcL0vg3Lm1IhfxZrH4u GQRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725439336; x=1726044136; 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=ylbiZHnndQyBxRrEPbsYoqCd5Ue19pmhRhZr0okk+70=; b=XPW9mTAs6A+9Z7o5qONmP4uMIT6+To2oVKOpqB6X6Gyn3zxzjEwjgBDXf0KsSm/cQZ LYD9EKbdWCxNxnMwv4tf42OfJZJ/dIcde5IfnyaAP/JPQey8bGqaxe4AJrbdLJ3VufEP X7LsH/rsP41sIJBuOUUmGRnDYmeYtZQ2WXtol0i3FiFJFDeZwn/MsIEtqQX1rCO7yzgU qwqVTPvOca0vTB5CJI7GTlDRIXeFGO3JbZuOLRnS1rrDR0nCsOZcO+6D5RoInk9w4f0t 1UOVPnroRntzH5YWjbGmFUa3WzmuqUQchSRzv3b8WBlZrIXDkIZJvfS+ZDNyvjMvMy8R Zs7w== X-Forwarded-Encrypted: i=1; AJvYcCXeQL8S6RHVgXi3xcV/JcSyFf9devi0ByXS13Y5bLrkXrQ3uGUJ4z/gxDiNw87YHM/nhcLzNvNafw==@kvack.org X-Gm-Message-State: AOJu0YwQ50EabcaL53iO87x8xsDECTHfMVjwgGj0AMR3MqdGlmQygyFC EAB8EHWHe0XRkxb6Pci1K5vT2ADmTPdtEpoy8Rcc8D5scDI0xVCYVFYqJLHEvms= X-Google-Smtp-Source: AGHT+IGRRbNTDVHBE5FEDByUohEYiQ4MupDiF5X1fYOKyMaX8J1f74Xy7lHxJ4SbBUityp3jftUwsg== X-Received: by 2002:a17:902:e848:b0:206:c43f:7896 with SMTP id d9443c01a7336-206c43f8dd5mr2410565ad.21.1725439336115; Wed, 04 Sep 2024 01:42:16 -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.42.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 01:42:15 -0700 (PDT) From: Qi Zheng <zhengqi.arch@bytedance.com> 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 <zhengqi.arch@bytedance.com> Subject: [PATCH v3 14/14] mm: khugepaged: retract_page_tables() use pte_offset_map_rw_nolock() Date: Wed, 4 Sep 2024 16:40:22 +0800 Message-Id: <20240904084022.32728-15-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 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 651A6A0002 X-Stat-Signature: on1wrjo8fia9atg4ay3u843a9pmy31fg X-Rspam-User: X-HE-Tag: 1725439337-817230 X-HE-Meta: U2FsdGVkX1+CgAUT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vgmD6Ht6IfyMgR3IRM0oMMXoUP3XL73ATgP1Ode5sCk48+l+rlvkJL/Qc7TIT/XOpUc62ER+4wTgOZE0P7Ji+vkfM750XbOe/pp/Mg7x01wxxa8t+cyADqasTgJZjqCI6g/Sdqo9SLoA1SWyA6F8fcNdgteq2WtKBFA7mzX4tK1Y8RqlwrF14T5GbN+i+gEMezaIt3SFixT4K9idZmX2TFpFxBmPn4Ogkj3DI/TZnhcDaxc7T4zKijmCeB902dFUyQd1LDdSEzzv3jxkZjEXXbekTe7/VWDMId8RUneZHsj/md5Bq0l1UaN1rXlrz/1JYwcrLf2GSfMSQWicjoaqI12OA== 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: <linux-mm.kvack.org> List-Subscribe: <mailto:majordomo@kvack.org> List-Unsubscribe: <mailto:majordomo@kvack.org> |
Series |
introduce pte_offset_map_{ro|rw}_nolock()
|
expand
|
diff --git a/mm/khugepaged.c b/mm/khugepaged.c index a117d35f33aee..318cc3eefb040 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1724,6 +1724,7 @@ static void retract_page_tables(struct address_space *mapping, pgoff_t pgoff) spinlock_t *pml; spinlock_t *ptl; bool skipped_uffd = false; + pte_t *pte; /* * Check vma->anon_vma to exclude MAP_PRIVATE mappings that @@ -1759,11 +1760,25 @@ static void retract_page_tables(struct address_space *mapping, pgoff_t pgoff) addr, addr + HPAGE_PMD_SIZE); mmu_notifier_invalidate_range_start(&range); + pte = pte_offset_map_rw_nolock(mm, pmd, addr, &pgt_pmd, &ptl); + if (!pte) { + mmu_notifier_invalidate_range_end(&range); + continue; + } + pml = pmd_lock(mm, pmd); - ptl = pte_lockptr(mm, pmd); if (ptl != pml) spin_lock_nested(ptl, SINGLE_DEPTH_NESTING); + if (unlikely(!pmd_same(pgt_pmd, pmdp_get_lockless(pmd)))) { + pte_unmap_unlock(pte, ptl); + if (ptl != pml) + spin_unlock(pml); + mmu_notifier_invalidate_range_end(&range); + continue; + } + pte_unmap(pte); + /* * Huge page lock is still held, so normally the page table * must remain empty; and we have already skipped anon_vma
In retract_page_tables(), we may modify the pmd entry after acquiring the pml and ptl, so we should also check whether the pmd entry is stable. Using pte_offset_map_rw_nolock() + pmd_same() to do it. Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com> --- mm/khugepaged.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)