Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2867077rwd; Fri, 2 Jun 2023 16:22:01 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6oS6/uHA9wudytiA7A/9KXa6PM8UCOGVQWYdya2HaWxH3aD6KAX93ZPNhpHvMX4WxwENtj X-Received: by 2002:a05:6870:a444:b0:19f:7312:79f2 with SMTP id n4-20020a056870a44400b0019f731279f2mr3396379oal.36.1685748120888; Fri, 02 Jun 2023 16:22:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685748120; cv=none; d=google.com; s=arc-20160816; b=fnO2kTeY/RVIlRZrnhSo+KwKcM36fEtoqU4kkvVlETIRZ53LzSqZznh+Cg9mx+XIsD +JYn5W90bxjPLqSuKV+bRXidxXWGl+4icNUpgtzKHA26GCpJ2zAuS1ws3+ZtqrPJU9Kl i88EK729GF6XNFXNdPRCPRHSGC6vCKaPemm9b/f0VQzwAFIpuvRXPmEm0vAJ45rTeFvQ 5rnc+sTsk+c9aVM67+bKz5JI37AL4qO0KZGDgiTFoW2liOlqlEhBMFuPgUldDiyd2bNZ 4/M6shejl8YGpOBji+xWyk/O2kqAuH2O8ZMwOCLySa01sp3/0+44s0cdS+fOZaorZqoc 1/gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kxigdMYXU7S1zIuZO/BNG/wM9sX6VFUiTJ8CdWEAXIc=; b=DSNsoT9minhniQmplRI1mHOe+sAU+GqHTFzzMvxbgrxL+8R96YkB0R4ArDPFpaV10N o4tne7p9u3GrYcTlSFM7FFI2GrvV2LpaZfPoWMEizI8bI4yRmZ5wYeNuAA+WGoe1LT18 NUuc6PRzkC3g0jNqcNaDK741L/B5YWvgQAymF9irXNuwbXl+28M+pXWxxdAKrpthl8Aq yP4Y60p0GrX/WkZdEmE853IBZUOsbMqgEggPfDN6cz3ou/R4sNekGH8Wmrzbdut4USX9 p6KynFZjm0hb3Rqr+Z6stGRfq3oMwTqs8ROsqqBNzmBvtCXsGWzwb0bqz0KyRy5Q1J7N SzHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Pkjwsb0T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i13-20020a636d0d000000b005348549fae5si1731299pgc.252.2023.06.02.16.21.48; Fri, 02 Jun 2023 16:22:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Pkjwsb0T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236825AbjFBXGx (ORCPT + 99 others); Fri, 2 Jun 2023 19:06:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236796AbjFBXGv (ORCPT ); Fri, 2 Jun 2023 19:06:51 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB83BE40 for ; Fri, 2 Jun 2023 16:06:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685747163; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kxigdMYXU7S1zIuZO/BNG/wM9sX6VFUiTJ8CdWEAXIc=; b=Pkjwsb0TYjCl2JucYwoEr1xtnZgkwH1BZYGvRIEzLwtlHWyJXQzDP4Eh+QUVNDNiNHeAca Q3vKWV1rKuiYkmV3DG5qggNrBXNNRu/RbTP+93co/H02ujyyPXz2HBxgXS0D7djI+TZ/Vt PvifEge0n9+meo31sMdy5JpI9sh8wdE= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-534-04oU9R1PPZ6WwMYtI_0zuQ-1; Fri, 02 Jun 2023 19:06:02 -0400 X-MC-Unique: 04oU9R1PPZ6WwMYtI_0zuQ-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-626380298d3so5604826d6.0 for ; Fri, 02 Jun 2023 16:06:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685747161; x=1688339161; 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=kxigdMYXU7S1zIuZO/BNG/wM9sX6VFUiTJ8CdWEAXIc=; b=i5TdcrqQmsbZRdMUeDdGIcER7iL2HTHxs1H2Q50roqbUrJEZmVaF0Q9yg2oOEPl6/9 6CmjkXu3BKbEftJDMeTVkaKNgsOZ7t2d8LX7K9tTTEAJYVxEKOdrTImSLzcPrnHi3YlZ veDWnGG3UxCacyTwXYJXkrqpVVnrtmVc7bask8ihMRKW1xZ62Cnw86iZAP0WLLjlILo/ Xj1hwsCb9deeso/7dQuttWUbXsyStkd+mHVFAF4zoPe3Is8Wu7vjJ0pmN6QQj1ThNWzS DI1T+buVSCZR4KT4bWCAdjJg+vm8AfIxy1SXTCqdMX1OJvPCHFXp1THXy1V+EQXIzi16 pJ8A== X-Gm-Message-State: AC+VfDxm9JOBecp+G/L0NCSYDlvf3B51k8fxWRohRLulYKExW1F+8HPN FEYOS9u8fPR3Oq67+cfJl1DvDLVFJGc/Sp+L6OacUZWKBHAiKzRgOGvBJxkVOFS1WeVMRANW1oy P2A4KX48qEOM/Sa5T7c44SmbIY2IbmcldzM+yfoOIs9CG5rk/LnfcGFElwDFDZhHDdrT5iTTSW6 VnukgEOA== X-Received: by 2002:a05:6214:509b:b0:61b:2111:c2e2 with SMTP id kk27-20020a056214509b00b0061b2111c2e2mr11674452qvb.2.1685747161381; Fri, 02 Jun 2023 16:06:01 -0700 (PDT) X-Received: by 2002:a05:6214:509b:b0:61b:2111:c2e2 with SMTP id kk27-20020a056214509b00b0061b2111c2e2mr11674414qvb.2.1685747161031; Fri, 02 Jun 2023 16:06:01 -0700 (PDT) Received: from x1n.. (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id px13-20020a056214050d00b0062607ea6d01sm1400792qvb.50.2023.06.02.16.05.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 16:06:00 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: David Hildenbrand , Alistair Popple , Andrew Morton , Andrea Arcangeli , "Kirill A . Shutemov" , Johannes Weiner , John Hubbard , Naoya Horiguchi , peterx@redhat.com, Muhammad Usama Anjum , Hugh Dickins , Mike Rapoport Subject: [PATCH 2/4] mm/migrate: Unify and retry an unstable pmd when hit Date: Fri, 2 Jun 2023 19:05:50 -0400 Message-Id: <20230602230552.350731-3-peterx@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230602230552.350731-1-peterx@redhat.com> References: <20230602230552.350731-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There's one pmd_bad() check, but should be better to use pmd_clear_bad() which is part of pmd_trans_unstable(). And I assume that's not enough, because there can be race of thp insertion when reaching pmd_bad(), so it can be !bad but a thp, then the walk is illegal. There's one case though where the function used pmd_trans_unstable() but only for pmd split. Merge them into one, and if it happens retry the whole pmd. Cc: Alistair Popple Cc: John Hubbard Signed-off-by: Peter Xu --- mm/migrate_device.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/mm/migrate_device.c b/mm/migrate_device.c index d30c9de60b0d..6fc54c053c05 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -83,9 +83,6 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp, if (is_huge_zero_page(page)) { spin_unlock(ptl); split_huge_pmd(vma, pmdp, addr); - if (pmd_trans_unstable(pmdp)) - return migrate_vma_collect_skip(start, end, - walk); } else { int ret; @@ -106,8 +103,10 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp, } } - if (unlikely(pmd_bad(*pmdp))) - return migrate_vma_collect_skip(start, end, walk); + if (unlikely(pmd_trans_unstable(pmdp))) { + walk->action = ACTION_AGAIN; + return 0; + } ptep = pte_offset_map_lock(mm, pmdp, addr, &ptl); arch_enter_lazy_mmu_mode(); -- 2.40.1