From patchwork Tue Sep 24 06:09:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13810128 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 E1AC4CF9C6B for ; Tue, 24 Sep 2024 06:11:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 729106B0096; Tue, 24 Sep 2024 02:11:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 68CC26B0098; Tue, 24 Sep 2024 02:11:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B5596B0099; Tue, 24 Sep 2024 02:11:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 21AF26B0096 for ; Tue, 24 Sep 2024 02:11:09 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id C71EBAC79E for ; Tue, 24 Sep 2024 06:11:08 +0000 (UTC) X-FDA: 82598609016.25.13C9875 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by imf19.hostedemail.com (Postfix) with ESMTP id EBB511A0006 for ; Tue, 24 Sep 2024 06:11:06 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=IaPGsugJ; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf19.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.172 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727158170; a=rsa-sha256; cv=none; b=5bcrJWuf2SLYfpqSNiYv/eJT4xs+81ppkjZTW2rhSP8UWw3crGXumjQlaxRM9KkS20Rryt SFc5aQP+Eij1SpBHkqOd+LAJ7xEvlMUlmIlPUghbEE2oIbvTFEeJi3v0cdpPE4FC2b81d1 CBeHs3fPmspdyUJ+svi//b3wW+yF488= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=IaPGsugJ; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf19.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.172 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=1727158170; 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=88oX8R3xcxvOkzUvzbp2hva7xyyimZKCI3msRz7gwSQ=; b=Hea/Z3DKl4YtQpCuu59i8LR7Z1fAVzP9LYZoQrJARgS0Ecb/zkX7FkcEjJCH5ScNHm5DxR 2k/LWwrqkNtmloCniWPSzuhkX8JJIye2trrAgKAN5+0ZPO1Bwo0YvWiwyMKAQzjQ+c+uxC KiB89BFTu1ubMWGcZ3B846SAr14Gj4Y= Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2059204f448so43655415ad.0 for ; Mon, 23 Sep 2024 23:11:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1727158266; x=1727763066; 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=88oX8R3xcxvOkzUvzbp2hva7xyyimZKCI3msRz7gwSQ=; b=IaPGsugJlB90ba6Vm6VOpO9bLc3FBH8JJrhwoIBCLf1r/0GcAtWWfaR6G4L55B2I8J LbD1mmhfUNPKQnayaw4L6NQrgy/z/ehNuYj9/e/EhNsHYTXpKcCb2CWPZid4tvvxK/wx yQLDepj1jBkftwu7CZ/pnYH6CeeOJHz0TVptNG/BhOxKvwdqOVezqZRzkodW32FVjJOz jjJW+6uCKIt+MGMqUSN6emQwdXmCKrstx6tt9B0wHbha8GfyVKyahYUhFBPHdxc/xtsC U9yIo+8yazVaz24U6BDwY9uTU91vJqJsmFtZorrOQ7NUG+ChvJZczrYKQneV+reNER56 hkVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727158266; x=1727763066; 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=88oX8R3xcxvOkzUvzbp2hva7xyyimZKCI3msRz7gwSQ=; b=i6F1Eexhvnow0/Znv5xg83Yv5Vk0wAGFnVookp1nJbnxFAtwBBnuY8ki0oHCIs2Et6 Q+jCf7wQL2Ses9c9Lj9Fp4zG1xl36UTvZLViWDXFvo7Wo8HWoWcN5p0dcVidhzbmIm6w BOfcniL1YrzKsYVptP1ttoQIf22CPAqhndC+YbcuMkqIYOLNRO7CwrtwbERu1G0grq3i 2F6HTHD+q+p+AA7G0ky4xXvui5BeEmlMAnbJ4H6PunUiRdGkMpkz6obsbNymC5fUFvoX cQhd6GOqbwCKcgoShxLuNzeAnaC2aAP90MDfJBiW5srePFkcsqJ6mpmaJ/AHM31U8GaO xcdg== X-Forwarded-Encrypted: i=1; AJvYcCU4AW1wE3fnJPKoGz51Y565PHXXWQFOWmLviDtzwKyQ0M9SR0ptCfxnsixkoqQher807hPKEsl+UA==@kvack.org X-Gm-Message-State: AOJu0YzXNPMU6m4CbRVlLhdZLeIaa+7Pq5lV8Rotz6A1TlsMqzXz0dfk e+xt7zTyY0J/BgYY+Ga1GUftYbHtezTbr46/KpjXXBNiv2yhKtLpjCNglyYVn78= X-Google-Smtp-Source: AGHT+IE0gKFIx3/KW4QPIJwQt51ZMLGla2X2YU2KRRy7vcX0w9t/15+gAAip1FE70+J7SP+04M4CVg== X-Received: by 2002:a17:902:d511:b0:205:7574:3b87 with SMTP id d9443c01a7336-208d980bb34mr182109485ad.15.1727158265764; Mon, 23 Sep 2024 23:11:05 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([63.216.146.178]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20af17229c9sm4344885ad.85.2024.09.23.23.11.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Sep 2024 23:11:05 -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 v4 06/13] mm: handle_pte_fault() use pte_offset_map_rw_nolock() Date: Tue, 24 Sep 2024 14:09:58 +0800 Message-Id: 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: EBB511A0006 X-Stat-Signature: i3nhws7toh1g436s9xjfuxbaczmsgngk X-Rspam-User: X-HE-Tag: 1727158266-61533 X-HE-Meta: U2FsdGVkX1+Ekw9E/vEfrj3QF19LtJl0MS80Y5ofYRqS9e/UqlSWzdz/qgBLsFSGss6bEL0JIfNplQ9SBAPPcssOKiw/8BiGl8UPVp2vbfFU8Hv7fTE9SjGpUEH+v0ZOcq8WxaNwoSkGTS75zkrixYHZ6POYXnhMMB3nNvxQZb1hn98SNrnCzZZ2zFZZ4+SWyh+cPxX9X49L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Iq68dt5euGJ9GyogCZuUIe0+rzyV/nnMEwCgtnq1+rZbJdnOq4EVzRZ3uK8P31uiNfEti1wvn37K0sschHIziw5K8s/nKSMVd3FFpsOqS6R1WwK9U9NXEENhHC57hNLF3vbxCQv4zTBxL0eTLcPhRftPlYYLVAPc0Ttm1dWUYTABS4JUA= 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 handle_pte_fault(), we may modify the vmf->pte after acquiring the vmf->ptl, so convert it to using pte_offset_map_rw_nolock(). But since we will do the pte_same() check, so there is no need to get pmdval to do pmd_same() check, just pass a dummy variable to it. Signed-off-by: Qi Zheng Acked-by: David Hildenbrand Reviewed-by: Muchun Song --- mm/memory.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index a245d28787034..6432b636d1ba7 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5750,14 +5750,24 @@ static vm_fault_t handle_pte_fault(struct vm_fault *vmf) vmf->pte = NULL; vmf->flags &= ~FAULT_FLAG_ORIG_PTE_VALID; } else { + pmd_t dummy_pmdval; + /* * A regular pmd is established and it can't morph into a huge * pmd by anon khugepaged, since that takes mmap_lock in write * mode; but shmem or file collapse to THP could still morph * it into a huge pmd: just retry later if so. + * + * Use the maywrite version to indicate that vmf->pte may be + * modified, but since we will use pte_same() to detect the + * change of the !pte_none() entry, there is no need to recheck + * the pmdval. Here we chooes to pass a dummy variable instead + * of NULL, which helps new user think about why this place is + * special. */ - vmf->pte = pte_offset_map_nolock(vmf->vma->vm_mm, vmf->pmd, - vmf->address, &vmf->ptl); + vmf->pte = pte_offset_map_rw_nolock(vmf->vma->vm_mm, vmf->pmd, + vmf->address, &dummy_pmdval, + &vmf->ptl); if (unlikely(!vmf->pte)) return 0; vmf->orig_pte = ptep_get_lockless(vmf->pte);