Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4368866imw; Tue, 19 Jul 2022 05:29:12 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vNexdJsYo1ksyif/ftTVr+mAglZ1zxStzBNl45c7ZNdH5AfPbtlEJvOjdTZFl71RmOG35F X-Received: by 2002:a05:6402:4488:b0:43a:7b6e:4b04 with SMTP id er8-20020a056402448800b0043a7b6e4b04mr43247372edb.202.1658233751835; Tue, 19 Jul 2022 05:29:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658233751; cv=none; d=google.com; s=arc-20160816; b=N8iCTIVzN2htredV+V41gj+Z0hyjGCfJ4X/kIM0AwVn8zwOB15mLQ9H9cRRY5zduRS BPwOC9heDZXjzyAGoFCEiXPJSz6yz/uNU4xA1VQoyex78Cj6mxIl/Sq/FEMJhTXkmra/ QPtgPwOpPwEkAIlB+9lJ7qHw+WTmsKinWCAZWFHoOYP44oZpu3+fHA1Q08jDDiiNAnMA YpjlhPwISlYYxr9ZQWxIYf0B8Plyqp4eBo5uP5utjOun8rJrVhTCNcP7fQlsc1j8yZfu h65LU2syz99R3F9uLQG9swQgtbGI06e/YQip+g6h81cbdggDbTGxFoXN4DC9Lyitf0Qa TGhA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=U0138gIYFcbiGE7m4utWWNkMGqStO8EA1JtfsSbfun0=; b=rLZxku6jw/+QsADmr3UE3V893RoYh9eWGWC0I+4CRI2TnubkepY15gMRSAn831DjsE HVRdkBqZWD+7lE3uhaW9oHzNkVlTj70uiRdaHrT1k5TMVFwis4H5+Hy5WHbQrrN8yued 7nwuCTFCd2a+Ax00rRFZbQouRJBHud63I1UDGqIsAoIR0+eRSj2Lvmp7LXvdYxU9Zhp7 FKjVOgi/9PFvd2GkOQWM3SZo4cTaHX26WHhO5WOj8MYqvJSWmoDk3K20EYpaq/UUJjfB q7Fu66prsu/M86/53eyAWAokcDkRNaHlrDIiV7lD3wohDdksPhlQBuustm9pvynLs6u1 mdrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Ns9FELmz; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l11-20020a056402254b00b0043ad7ac3be3si20234697edb.543.2022.07.19.05.28.45; Tue, 19 Jul 2022 05:29:11 -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=@linuxfoundation.org header.s=korg header.b=Ns9FELmz; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237313AbiGSL5e (ORCPT + 99 others); Tue, 19 Jul 2022 07:57:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237552AbiGSL5H (ORCPT ); Tue, 19 Jul 2022 07:57:07 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0E8B45047; Tue, 19 Jul 2022 04:56:34 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 2E1D2B81B2B; Tue, 19 Jul 2022 11:56:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62FEFC341C6; Tue, 19 Jul 2022 11:56:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658231791; bh=TmlIuGAFf4iWItn3vvi9s8uj6/bFJy5bVeZmAv6p1zU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ns9FELmzGSatld+CAkBlmTg634UkWulolu7XJFiK2r5mTZbwr8HRL97sO4WMMDZEK oXokMGHxu5BjGlofC1Y7iSNpg68CfVBov1t3Sn7cEz7wJ5fgNf/A0KojdRTlBnVzIY 9pjwFvkDqwkBIX3PEsiAcYEuArr9pEj9lJNwP604= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Rik van Riel , Miaohe Lin , Naoya Horiguchi , Oscar Salvador , John Hubbard , Mel Gorman , Johannes Weiner , Matthew Wilcox , Andrew Morton , Linus Torvalds , Sudip Mukherjee Subject: [PATCH 4.9 27/28] mm: invalidate hwpoison page cache page in fault path Date: Tue, 19 Jul 2022 13:54:05 +0200 Message-Id: <20220719114458.617197379@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220719114455.701304968@linuxfoundation.org> References: <20220719114455.701304968@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 From: Rik van Riel commit e53ac7374e64dede04d745ff0e70ff5048378d1f upstream. Sometimes the page offlining code can leave behind a hwpoisoned clean page cache page. This can lead to programs being killed over and over and over again as they fault in the hwpoisoned page, get killed, and then get re-spawned by whatever wanted to run them. This is particularly embarrassing when the page was offlined due to having too many corrected memory errors. Now we are killing tasks due to them trying to access memory that probably isn't even corrupted. This problem can be avoided by invalidating the page from the page fault handler, which already has a branch for dealing with these kinds of pages. With this patch we simply pretend the page fault was successful if the page was invalidated, return to userspace, incur another page fault, read in the file from disk (to a new memory page), and then everything works again. Link: https://lkml.kernel.org/r/20220212213740.423efcea@imladris.surriel.com Signed-off-by: Rik van Riel Reviewed-by: Miaohe Lin Acked-by: Naoya Horiguchi Reviewed-by: Oscar Salvador Cc: John Hubbard Cc: Mel Gorman Cc: Johannes Weiner Cc: Matthew Wilcox Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds [sudip: use int instead of vm_fault_t and adjust context] Signed-off-by: Sudip Mukherjee Signed-off-by: Greg Kroah-Hartman --- mm/memory.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) --- a/mm/memory.c +++ b/mm/memory.c @@ -2891,10 +2891,15 @@ static int __do_fault(struct fault_env * } if (unlikely(PageHWPoison(vmf.page))) { - if (ret & VM_FAULT_LOCKED) + int poisonret = VM_FAULT_HWPOISON; + if (ret & VM_FAULT_LOCKED) { + /* Retry if a clean page was removed from the cache. */ + if (invalidate_inode_page(vmf.page)) + poisonret = 0; unlock_page(vmf.page); + } put_page(vmf.page); - return VM_FAULT_HWPOISON; + return poisonret; } if (unlikely(!(ret & VM_FAULT_LOCKED)))