From patchwork Thu Sep 26 06:46:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13812862 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 B5DD8CCF9E9 for ; Thu, 26 Sep 2024 06:47:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 54BC96B00A6; Thu, 26 Sep 2024 02:47:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4FBFE6B00A8; Thu, 26 Sep 2024 02:47:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3C3316B00AA; Thu, 26 Sep 2024 02:47:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 1C14F6B00A6 for ; Thu, 26 Sep 2024 02:47:37 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id DC71D4083B for ; Thu, 26 Sep 2024 06:47:36 +0000 (UTC) X-FDA: 82605958512.08.DA749C7 Received: from mail-qt1-f172.google.com (mail-qt1-f172.google.com [209.85.160.172]) by imf29.hostedemail.com (Postfix) with ESMTP id 1098B120003 for ; Thu, 26 Sep 2024 06:47:34 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=UKJaeZOM; spf=pass (imf29.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.160.172 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727333135; 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=FGfpWKdmzK0jnK1PWirIO4gdjX69d4dGsCK5egCJil8WVCRBVtzdsbGCZ9QMEfkngIYrZG hZAxTEkW8s+z2ssWbz57+XpybS9rBd0EHfXnngxdlFurZjuPMiMmIw6jTL2VlnllEAgiY7 ajft3GpoUy4r2L0LjQK0EbGFW4ol0ME= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727333135; a=rsa-sha256; cv=none; b=NK99ECrm/MWrSHkshYmO+i0l0nvhiHSEr49w5iJe7QP0cRo4YIF3Rtz+CECppljlX9V9ce qKokKmzQtEy2FGBj0QBSjkAuDSXGEmKxgwoDipatRIa12NC8EsbF0k+Y8fsE/+Kmr0KfE+ ch2708gfeZvEPEoNXzpj5gjo+35xaeM= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=UKJaeZOM; spf=pass (imf29.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.160.172 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-qt1-f172.google.com with SMTP id d75a77b69052e-45aeef3ce92so3444551cf.2 for ; Wed, 25 Sep 2024 23:47:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1727333254; x=1727938054; 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=UKJaeZOMGdsQeZVBP2kjkdS1qsw4Bc9pDJIM92X0xBW9mrv/EE0M+7TWzDlwggcVeQ ZcNekqKwSlhKdjcC4QFuAZBGzhb3CfIu/ILNZ7acYb9AzC4qd31lfzMc0N0FKQTWCkcE tYx0hAFf+LksEleK5gkLlPRYn7QW6pcoZBRkk+xXe/yalJaQ8EqttSIBhHF6XxIe9M/L Ns/+mVVJ1B6msW0fqvsOswx98IiBWQB61SRG+A7vtI3FiFGMAegkOL6c3Bk0DgdmsXEd V5oz/es14AWJ0Xk5peZRwXvMhfyeSF4oROkMCjLtvSBO32zcz2wkGx8I3AxXwe6UgbPw 9JQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727333254; x=1727938054; 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=lcyF0omaPySjXxqNisMPkmsCvAcVMTsYr0NDmjp0NBaHoeDdiCcRy82IA/aDgjyuKn zT3YrQxM2sfNocPwJfm45Ggm/WNjXl2HQd9hpgr0a7foGNmMPcQfoKncxnAe4+XZK6/1 LwsTKVGgMNN3L/Hw/IB8xPCVfFGppkj0XMMUty6Dz2SfNKj75gGTi4QAZ8NZCqH9DgGU ghD51cK0E1rHlaMUS0FPZbuSxpVwGH6C1OE29GowX0xIamdw7nOLO+u0CyJZw2+yVGVQ ckn3SXoBR2FM0Av+oSjUINe7yqc2oXPxkGpk5zXMR3irSqIHKrhXeAir46Oq4yOfKNdy 2kHQ== X-Forwarded-Encrypted: i=1; AJvYcCUh7LypOtNH06zkZIYtx4pXcwEL1RZxeUaWAcasREj/DqWC18A5npN5RBHyvUs8NvYpeWjMObKdkw==@kvack.org X-Gm-Message-State: AOJu0YxWh32pr56OytIFmul+PGyNpez857veAm65n01/zZYbQ+5mFIFu BdjicbKKsYRFVRJGP15wh/TOHbot67lDoeju88GpQDP7Xvo88JYZUimRe1458Ek= X-Google-Smtp-Source: AGHT+IEkNfjkqcOSOf8WFqyh7ycpXwLGwDHOuzbRwWfPgE4JYY85w8LbZC4JktZjOBGqNKfXWcA2mg== X-Received: by 2002:ac8:5a43:0:b0:458:3824:a083 with SMTP id d75a77b69052e-45b5def43dcmr69885101cf.32.1727333254117; Wed, 25 Sep 2024 23:47:34 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.150]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-45b5257ff1esm23024611cf.38.2024.09.25.23.47.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Sep 2024 23:47:33 -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 v5 06/13] mm: handle_pte_fault() use pte_offset_map_rw_nolock() Date: Thu, 26 Sep 2024 14:46:19 +0800 Message-Id: X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 1098B120003 X-Stat-Signature: 6oim55e49hif4bad3npb3jkoz6xbjrsr X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1727333254-528989 X-HE-Meta: U2FsdGVkX1+u5WN1FGG94iWk4SbcimNHh3GmFsuAAE/oVpE6MjutYJDuMeZmsCXAcZfRePyAimZ/PWJUSMtU5kWV33zHchSL/DEEYn2b76NdDpapyP87YoqdcjwGc7rNBEJOF3woISeZhudXvm/8C1sViE4hPOLAtw28m4M+WgFvLMX97MqTpnT10FOAawMyvVxIsVzbc9+yD+9w3IAP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G3PgtjUDrGw0VXP8EiUNQbTFkEZxMv2D/Nl9rZsjj3EjbwwIBDAq0UBF2f7IFri7s1GSjn+6ZuefUrUjB0HaPSan5J8vWvPl/OwzanpBWdoDAwU4AxofH9cRkylLG7v1olW3uZvtWbxoYhh7tkhlW9ZclRFy/CdcaL3JP9kjg= 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);