Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp515355pxb; Fri, 16 Apr 2021 11:01:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxO8rAIuJRyWvfFddeKH2toJTR0LkTpVjmT3C5gM4DZ4RmuYos06ik9R3ZCUdnNW37Sqn9x X-Received: by 2002:a17:906:5413:: with SMTP id q19mr9788800ejo.8.1618596082410; Fri, 16 Apr 2021 11:01:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618596082; cv=none; d=google.com; s=arc-20160816; b=GJGZz+5fqNYmsiZ43VhW9kXZ24Kb9i11Lldl68pMbMHZ8mqdcdkz9fyW+PdETFJUEy EGN+1qFLCeRdGqA/X0v6VRCsFKzkrnQl7eCNJqzhAhSQRDemW7WEab8wb6PQd+7y6cNA p5QCU4ykhUdysLyf3fxhualry5DTgRexw/y1jdzhhTkRnCzj1ZmdDG8FRXvmsZYj3beE aDiOnDL1b87Ssa7xM1TQyU9zeU63zSbUuGxoQvumMR1QOrZBj3WwEq5rS9sVtC+Nm8pq lH+UB8K7ivVPMqfVM8ORyOh/9/0VzK1AjGsWHxR5EO0nQO7dppyfSoBw8RUgIWOzFPkG deWg== 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=59bj20q2jA8jwhgH+O16mbf2BCDmtwqEwb3cf3INn5E=; b=kShTEPtWhbYN5eRAcb6Odt26qUjXTYiD2gPMxG9THD5CVcNCiaCvP9YWhVxZsh95Bn 8qSo7NZy/e+K69mz0yWv27XpArTA3alvZvhtGfZtyhfvJ+kIM5EsmkvLfTmYi02NHCQZ bRy0dU9dL9LA1Dk9ALQbNNoznYk/2lZfjhQojGF7EyCkd9C6p36cqky3Ka0wLABWwwBy vH7Ahi/81tZ8fjgNUWF+2ij+TBOV++ntyY+BLufbI1b3WsxrrEU4CLPjV92RFQo6wsEm uxalct8qYjFdcpKSQBXWNGOdhe8VoLGtWVRRDivGz+z/HPxIojtoOYB9d91PxSY0DpQA Hf6w== 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 a11si5272205ejs.551.2021.04.16.11.00.58; Fri, 16 Apr 2021 11:01:22 -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 S1344063AbhDPPm0 (ORCPT + 99 others); Fri, 16 Apr 2021 11:42:26 -0400 Received: from mga17.intel.com ([192.55.52.151]:10800 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343992AbhDPPmL (ORCPT ); Fri, 16 Apr 2021 11:42:11 -0400 IronPort-SDR: wfem44kkoBDDVcbXMsVSG37pJir2Mo55HGtqbltnwwhHGatu/HRpw7VeaD4HppdxlhYfhaxR0H 4eVLQDpBwSHQ== X-IronPort-AV: E=McAfee;i="6200,9189,9956"; a="175163938" X-IronPort-AV: E=Sophos;i="5.82,226,1613462400"; d="scan'208";a="175163938" 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: BiatwMA0y8qUcIW7/n3v5VFpxjtDSkQkoZb1k+sB1Z4cLkxVSZkRIORtiu9iZm6VdBUjhLkGV4 eMT6uG8NXbTQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,226,1613462400"; d="scan'208";a="422038787" 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 41BE135E; 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 11/13] mm: Replace hwpoison entry with present PTE if page got unpoisoned Date: Fri, 16 Apr 2021 18:41:04 +0300 Message-Id: <20210416154106.23721-12-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 If the page got unpoisoned we can replace hwpoison entry with a present PTE on page fault instead of delivering SIGBUS. Signed-off-by: Kirill A. Shutemov --- mm/memory.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/mm/memory.c b/mm/memory.c index b15b0c582186..56f93e8e98f9 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3280,7 +3280,43 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) vmf->page = device_private_entry_to_page(entry); ret = vmf->page->pgmap->ops->migrate_to_ram(vmf); } else if (is_hwpoison_entry(entry)) { - ret = VM_FAULT_HWPOISON; + page = hwpoison_entry_to_page(entry); + + locked = lock_page_or_retry(page, vma->vm_mm, vmf->flags); + if (!locked) { + ret = VM_FAULT_RETRY; + goto out; + } + + vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, + vmf->address, &vmf->ptl); + + if (unlikely(!pte_same(*vmf->pte, vmf->orig_pte))) { + ret = 0; + } else if (PageHWPoison(page)) { + ret = VM_FAULT_HWPOISON; + } else { + /* + * The page is unpoisoned. Replace hwpoison + * entry with a present PTE. + */ + + inc_mm_counter(vma->vm_mm, mm_counter(page)); + pte = mk_pte(page, vma->vm_page_prot); + + if (PageAnon(page)) { + page_add_anon_rmap(page, vma, + vmf->address, false); + } else { + page_add_file_rmap(page, false); + } + + set_pte_at(vma->vm_mm, vmf->address, + vmf->pte, pte); + } + + pte_unmap_unlock(vmf->pte, vmf->ptl); + unlock_page(page); } else { print_bad_pte(vma, vmf->address, vmf->orig_pte, NULL); ret = VM_FAULT_SIGBUS; -- 2.26.3