From patchwork Thu Aug 10 08:58:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yan Zhao X-Patchwork-Id: 133902 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp342632vqi; Thu, 10 Aug 2023 04:16:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEg7ibtxQ3kCBni58ovuI7eevncG6yNl3R7JZXQUipoRr0fuQUZUHGOYJncAHvfAQ0mbV2V X-Received: by 2002:a17:902:a606:b0:1bc:3f9b:d96 with SMTP id u6-20020a170902a60600b001bc3f9b0d96mr1468435plq.49.1691666163299; Thu, 10 Aug 2023 04:16:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691666163; cv=none; d=google.com; s=arc-20160816; b=btlrMMeFVXi4SjnwZFoJvk0IMgVmIzLx3W1K8wYEahhv4e4gNuQmCDGkKimDGoVvYw 2nk0wKyiEoL4fHfiyZRj6oom6Co2JDDSg6lP8qHLinp3hIJ5hlGLO2gT9aDWdxuueFVt EY9RPm1OoNlqAR1zlLOchdM7tLiRiDuhuf5NH6pOsJ7OOaH4oivqKajrPihkFv7qcSWK 7GuHYqKwYKFp+xleNjGOoADSfSnO1I9Tmgal24lraS8BvwFuAZyeSYF/LHS2l45LdU8V cy4jc0jLQNylduoOu+Ft249hA5Zly7mV7Gn+2j9l9ViKV+H7JNyPRjM7CD6CyzlkJLk3 fVvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=SxloWDV3h+sdKOmXK4HSVovGWLEgXVGeioIvdwHwjaU=; fh=o8CQ29xf3wsMGvtht3Cn61yxgqhXwJk0ZYd3HveN8Mc=; b=IwaeMp8wBdqJ2VCyxiVZDRIbNi7YBtM20IQiSYVVRq84BmRMxcJfGW4wdXFzkVjdOl 3EL0omno3xRKNOShvJ5QKSaUuntyawvcsMpo90L2aL+4gho1vHu/gE3YIaJcHh4kZOSK q+OPlXoTipixBwawiHByIGWA1K/ofH/CkqI6PxBpfrbB40uVmoenftWuzAT/diSL+agd QGzdMPd/0TT8k7tcYgAAUjzTeDi0PQfNVnWskED/Vw+REIBls/SSpmG364y/swD4U2db AfixfiGIsey60xiMLF7ZXGZ8gurmkmIvZz9ThSOyQcpJ7wUk7O7YwlAPoshui/lmm3ey CXNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gVGzE4sy; 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=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p1-20020a170902e74100b001bbaaf979a4si1322708plf.360.2023.08.10.04.15.49; Thu, 10 Aug 2023 04:16:03 -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=@intel.com header.s=Intel header.b=gVGzE4sy; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233730AbjHJJZV (ORCPT + 99 others); Thu, 10 Aug 2023 05:25:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231405AbjHJJZU (ORCPT ); Thu, 10 Aug 2023 05:25:20 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3C3A213F; Thu, 10 Aug 2023 02:25:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1691659519; x=1723195519; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=n1Msk62xu+U/2i8oJmw01jY05sFs/JrR7DH8MV3GHPs=; b=gVGzE4syAmyLeFTLq7q/I6Zw8D5pDr2UAigi0IPM3fWXkSJP7WeVbpNA ihHP2Mt5mc6GttJLAYvVnutUi2C4zDzBj0e654hLQLfl+q0gDMq3ZPOo8 Lqi4WmyOuBT/Vnot79P3T5pvKwzYob2fP1AYs7gHe2G4+HIBUCSAOD+gZ HWPnz3gGWTdcrha34ZVlBbOuGcAxF6WYv//NpvUH6HZ8UbWk94NWNxOBK wsCQPAruSC9bpPHeeTzQJ45GpvUPfU91v9aNTbfgljd+7/Y0ODnCZ+5Yo SBqcP63A6tT5MdcMTTNhQ3EJgsC/qpLvnmPvhI4pnXQveC8IT7smnBgOA A==; X-IronPort-AV: E=McAfee;i="6600,9927,10797"; a="374123736" X-IronPort-AV: E=Sophos;i="6.01,161,1684825200"; d="scan'208";a="374123736" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Aug 2023 02:25:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10797"; a="855867318" X-IronPort-AV: E=Sophos;i="6.01,161,1684825200"; d="scan'208";a="855867318" Received: from yzhao56-desk.sh.intel.com ([10.239.159.62]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Aug 2023 02:25:16 -0700 From: Yan Zhao To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: pbonzini@redhat.com, seanjc@google.com, mike.kravetz@oracle.com, apopple@nvidia.com, jgg@nvidia.com, rppt@kernel.org, akpm@linux-foundation.org, kevin.tian@intel.com, david@redhat.com, Yan Zhao Subject: [RFC PATCH v2 2/5] mm: don't set PROT_NONE to maybe-dma-pinned pages for NUMA-migrate purpose Date: Thu, 10 Aug 2023 16:58:25 +0800 Message-Id: <20230810085825.26038-1-yan.y.zhao@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230810085636.25914-1-yan.y.zhao@intel.com> References: <20230810085636.25914-1-yan.y.zhao@intel.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773840539255788625 X-GMAIL-MSGID: 1773840539255788625 Don't set PROT_NONE for exclusive anonymas and maybe-dma-pinned pages for NUMA migration purpose. For exclusive anonymas and page_maybe_dma_pinned() pages, NUMA-migration will eventually drop migration of those pages in try_to_migrate_one(). (i.e. after -EBUSY returned in page_try_share_anon_rmap()). So, skip setting PROT_NONE to those kind of pages earlier in change_protection_range() phase to avoid later futile page faults, detections, and restoration to original PTEs/PMDs. Signed-off-by: Yan Zhao --- mm/huge_memory.c | 5 +++++ mm/mprotect.c | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index eb3678360b97..a71cf686e3b2 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1875,6 +1875,11 @@ int change_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma, goto unlock; page = pmd_page(*pmd); + + if (PageAnon(page) && PageAnonExclusive(page) && + page_maybe_dma_pinned(page)) + goto unlock; + toptier = node_is_toptier(page_to_nid(page)); /* * Skip scanning top tier node if normal numa diff --git a/mm/mprotect.c b/mm/mprotect.c index cb99a7d66467..a1f63df34b86 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -146,6 +146,11 @@ static long change_pte_range(struct mmu_gather *tlb, nid = page_to_nid(page); if (target_node == nid) continue; + + if (PageAnon(page) && PageAnonExclusive(page) && + page_maybe_dma_pinned(page)) + continue; + toptier = node_is_toptier(nid); /*