Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp3908491pxb; Mon, 21 Feb 2022 08:06:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJz37gGkGqLQMngWJvHnKkJU6iDOZURQbu+HHHtD8quLraA0TyQN0jXOE8Npdo9Eomo8j+SV X-Received: by 2002:a63:da06:0:b0:372:f5c5:8f92 with SMTP id c6-20020a63da06000000b00372f5c58f92mr16750033pgh.311.1645459603293; Mon, 21 Feb 2022 08:06:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645459603; cv=none; d=google.com; s=arc-20160816; b=ajL/73f/d+kTV+JGcbb1WakfTw/3kgaolQdR8mJ+v264WY78WaifhFGIv96PTOj9Yy CqoNFHxUyDzaajdKOI65bBGSrnPndSuVdZB2X7fPS2cBs3awrW6+D6i/v17XXRSgFvkd KvdipbmlOx2BqZy45z5+WDHbg37DM8bdIwE+eRHFCP0Qc1cpolkb9hqBUxEh/krRy3jk SlBAeoOzMoZHKesQBIDwDqBrKp9BDpbeviCX52/4XnPJlzSfXDLBlb9XByR+qJHzKoz4 uqwCg9RZKimws/mxrIEAMO6waOhBbrpI53jAutDqlHPvvBGw79B/7Ad4k2zypLFdnrSH Byow== 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=O3hxsKB8i11YIb3kXl72VXTO8fBEDgJ+TMesiKxomFw=; b=HKcVGbf8mTFGv+YyfeCfEyUPmTXyT3ZigssS0ICvMr1S1DzydhePZxop+cozGwbz1I zmtNeRGCsBUdctGvz4SN3YOL8oFS46TNVwwpSwQIPd1PxYtkRM1x6w1zbefGQatb6tB9 mk26uhQXM96oOwoA0gy/lI/PXmXK/rTPjsXz99Das/o+tXG4SUZ6h3tX5yh+fWaPaOUt cqGU3q9Vj9wbGr6cNPL8PHnVrNs70LParg0zBV63QCyHtBnuSSWNi5ni6AikcGe5kgGw E64Tx1yhZkTa+9PDKaZq4gCyhTXCURImBSBuehvO8JDtAP4uONXE8f4wq99UFdW/ljHK g2LA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EagVCQNw; 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 bf6si10705767pgb.31.2022.02.21.08.06.26; Mon, 21 Feb 2022 08:06:43 -0800 (PST) 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=EagVCQNw; 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 S1352277AbiBUJrT (ORCPT + 99 others); Mon, 21 Feb 2022 04:47:19 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:49112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349320AbiBUJkH (ORCPT ); Mon, 21 Feb 2022 04:40:07 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F9673BFA3; Mon, 21 Feb 2022 01:17:19 -0800 (PST) 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 dfw.source.kernel.org (Postfix) with ESMTPS id C06C060F04; Mon, 21 Feb 2022 09:17:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A6070C340EB; Mon, 21 Feb 2022 09:17:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1645435027; bh=jpZH6xrh9hccXtiZXWyWHqnt+rfjkT9gFkXP6XsvMPw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EagVCQNwmWmN/WKIgAsDFiPmCJybQ9RJY4f6hOO7SSUO3Lm+Ti+DotrJwlxyNjD7S CFDy3T105/DxpgiEBBWajk+TkWVAr3Xha0tHhhgAIVXVLWSKoLslPUjMoI3KocQP6x jBzlZl1n9/sggH1EkdWg+k3c9lQkUQ2/Ul+eAd1E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Hildenbrand , Peter Xu , Linus Torvalds , Oded Gabbay Subject: [PATCH 5.16 019/227] mm: dont try to NUMA-migrate COW pages that have other uses Date: Mon, 21 Feb 2022 09:47:18 +0100 Message-Id: <20220221084935.476424505@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220221084934.836145070@linuxfoundation.org> References: <20220221084934.836145070@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.1 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,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 From: Linus Torvalds commit 80d47f5de5e311cbc0d01ebb6ee684e8f4c196c6 upstream. Oded Gabbay reports that enabling NUMA balancing causes corruption with his Gaudi accelerator test load: "All the details are in the bug, but the bottom line is that somehow, this patch causes corruption when the numa balancing feature is enabled AND we don't use process affinity AND we use GUP to pin pages so our accelerator can DMA to/from system memory. Either disabling numa balancing, using process affinity to bind to specific numa-node or reverting this patch causes the bug to disappear" and Oded bisected the issue to commit 09854ba94c6a ("mm: do_wp_page() simplification"). Now, the NUMA balancing shouldn't actually be changing the writability of a page, and as such shouldn't matter for COW. But it appears it does. Suspicious. However, regardless of that, the condition for enabling NUMA faults in change_pte_range() is nonsensical. It uses "page_mapcount(page)" to decide if a COW page should be NUMA-protected or not, and that makes absolutely no sense. The number of mappings a page has is irrelevant: not only does GUP get a reference to a page as in Oded's case, but the other mappings migth be paged out and the only reference to them would be in the page count. Since we should never try to NUMA-balance a page that we can't move anyway due to other references, just fix the code to use 'page_count()'. Oded confirms that that fixes his issue. Now, this does imply that something in NUMA balancing ends up changing page protections (other than the obvious one of making the page inaccessible to get the NUMA faulting information). Otherwise the COW simplification wouldn't matter - since doing the GUP on the page would make sure it's writable. The cause of that permission change would be good to figure out too, since it clearly results in spurious COW events - but fixing the nonsensical test that just happened to work before is obviously the CorrectThing(tm) to do regardless. Fixes: 09854ba94c6a ("mm: do_wp_page() simplification") Link: https://bugzilla.kernel.org/show_bug.cgi?id=215616 Link: https://lore.kernel.org/all/CAFCwf10eNmwq2wD71xjUhqkvv5+_pJMR1nPug2RqNDcFT4H86Q@mail.gmail.com/ Reported-and-tested-by: Oded Gabbay Cc: David Hildenbrand Cc: Peter Xu Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/mprotect.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -94,7 +94,7 @@ static unsigned long change_pte_range(st /* Also skip shared copy-on-write pages */ if (is_cow_mapping(vma->vm_flags) && - page_mapcount(page) != 1) + page_count(page) != 1) continue; /*