Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp444012pxb; Fri, 16 Apr 2021 09:17:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcW+g179P0IR/DZeUHsZDSlvsFNrQMg0NcnltmbPwcODZoHLkHxMSTGx6pDJ6YKjePkMeo X-Received: by 2002:a17:906:6d0a:: with SMTP id m10mr8868043ejr.538.1618589839730; Fri, 16 Apr 2021 09:17:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618589839; cv=none; d=google.com; s=arc-20160816; b=seE6zhzx8JJ4FgkbK+ZkMCWk2pti8bEda6XW7hNdi5kuC7UplkwWJC1BHbYcyW+yR5 76FEwRbyU3WK/0f8nlpJQa4Jcv7SI1Is2cwrW2s97NYq/hvuBnk/3f++44fqtLJYnrjI /45JafSLV4EQWxwQ2v4O/jyb3q7xRc6eUfmTK5M9Zt/0ug7VR6H1Q2EWobX60cK67pn+ Ccd2FDrQkWjjxhO5xOhv0UwZTYUXf6zDNX1nEZIq5Rl8JFSBVzGPla/DfUad3uLgjKt2 p/KIQUT4LkzYdIInYh1H3DDvCRZ9y7cg63orhd8PrBRtrc/XtQ007ndC1HOQhKrEgFIW hW3g== 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 :ironport-sdr:ironport-sdr; bh=Pc6ZoPwlum8Jc2F4ViitdlCtdbl82b/Du+aV39N97jw=; b=c+yb4Fr6pwlAvsSoVSjuOzlJmdAcalVl0ZiiBCMvldWs03KwxZ9dOepyWlaKMVLysj wm7IOB/vGuDcmxQD6t46rkT+IB7rtB1fITfy1JTDIdf3TnqnPK0eO5PkC3G95L+eFvHo 1za6FwJdqAA7hs1WeJl17he1g0lgjf8yHx1hlNJPllGHjQZz9xAdW4uxMqiXCC7tjtw6 hVjlGZkHsWD4JUH2NRHJFIUB+zRREojR05NjxFyZkUK9qoIOz6qnUBcvirigtxqJM1ol qcRC1YT1HAk+FlauY46Q7LzQP5NrPZ73dsDn9e+3DWoV4IWDl0egDcQaadjD+QAJE+a9 USrg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jl3si5292798ejc.488.2021.04.16.09.16.56; Fri, 16 Apr 2021 09:17:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237525AbhDPPmb (ORCPT + 99 others); Fri, 16 Apr 2021 11:42:31 -0400 Received: from mga17.intel.com ([192.55.52.151]:10803 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343993AbhDPPmL (ORCPT ); Fri, 16 Apr 2021 11:42:11 -0400 IronPort-SDR: n94Lt51jOBkjwKnaxLRjWZf5zBWf0bQKIEMond6YyUHQWUshn8yykoqnre/dHhzze7+koInlWM gCrBE7ugeHVQ== X-IronPort-AV: E=McAfee;i="6200,9189,9956"; a="175163937" X-IronPort-AV: E=Sophos;i="5.82,226,1613462400"; d="scan'208";a="175163937" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Apr 2021 08:41:43 -0700 IronPort-SDR: GV2YKh3YQQwBbOm00/MLd7uBYxj/MRkz8+eXvddmWNUVHa4PpCVjoCFf3t4suV3PJ2PGTLh9zq X73Pit5nhcWQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,226,1613462400"; d="scan'208";a="422038785" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga007.jf.intel.com with ESMTP; 16 Apr 2021 08:41:38 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 35AC835A; Fri, 16 Apr 2021 18:41:50 +0300 (EEST) From: "Kirill A. Shutemov" To: Dave Hansen , Andy Lutomirski , Peter Zijlstra , Sean Christopherson , Jim Mattson Cc: David Rientjes , "Edgecombe, Rick P" , "Kleen, Andi" , "Yamahata, Isaku" , Erdem Aktas , Steve Rutherford , Peter Gonda , David Hildenbrand , x86@kernel.org, kvm@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [RFCv2 10/13] mm: Keep page reference for hwpoison entries Date: Fri, 16 Apr 2021 18:41:03 +0300 Message-Id: <20210416154106.23721-11-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210416154106.23721-1-kirill.shutemov@linux.intel.com> References: <20210416154106.23721-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On migration we drop referece to a page once PTE gets replaced with a migration entry. Migration code keeps the last reference on the page that gets dropped once migration is complete. We do the same for hwpoison entries, but it doesn't work: nobody keeps the reference once page is remapped with hwpoison entries. Keep page referenced on setting up hwpoison entries, copy the reference on fork() and return on zap(). Signed-off-by: Kirill A. Shutemov --- mm/memory.c | 6 ++++++ mm/rmap.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/mm/memory.c b/mm/memory.c index feff48e1465a..b15b0c582186 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -767,6 +767,9 @@ copy_nonpresent_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm, pte = pte_swp_mkuffd_wp(pte); set_pte_at(src_mm, addr, src_pte, pte); } + } else if (is_hwpoison_entry(entry)) { + page = hwpoison_entry_to_page(entry); + get_page(page); } set_pte_at(dst_mm, addr, dst_pte, pte); return 0; @@ -1305,6 +1308,9 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, page = migration_entry_to_page(entry); rss[mm_counter(page)]--; + + } else if (is_hwpoison_entry(entry)) { + put_page(hwpoison_entry_to_page(entry)); } if (unlikely(!free_swap_and_cache(entry))) print_bad_pte(vma, addr, ptent, NULL); diff --git a/mm/rmap.c b/mm/rmap.c index 08c56aaf72eb..f08d1fc28522 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1575,7 +1575,7 @@ static bool try_to_unmap_one(struct page *page, struct vm_area_struct *vma, dec_mm_counter(mm, mm_counter(page)); set_pte_at(mm, address, pvmw.pte, pteval); } - + get_page(page); } else if (pte_unused(pteval) && !userfaultfd_armed(vma)) { /* * The guest indicated that the page content is of no -- 2.26.3