Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4425749pxb; Mon, 21 Feb 2022 21:14:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJxWFq2e/xcEBIaR4hETpUAAASNeB8WX4mCGk7HbWrgK8xhTDmgGH54pTwtJREW6XVmFHKFE X-Received: by 2002:a05:6a00:1691:b0:4e1:935f:94dd with SMTP id k17-20020a056a00169100b004e1935f94ddmr23123195pfc.83.1645506841633; Mon, 21 Feb 2022 21:14:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645506841; cv=none; d=google.com; s=arc-20160816; b=y1rqyeMzniKfANlINQVmwuOzypzMjNZQtgmUV/oevxAorYb6lQcqng30TPsPen3+l3 4N7bLpP9OpQGkZRUpqTbJc2IAyDw3elJt9+jzqq7Ih9HLkAjiLWwF++zmZiH47sBT66W MtPjE7b1U7NoEP6cIJlo2fpqeyr1Li+PRumSPbhAIr3vmx++9mZckEYJ56E7N9lpfVo2 tuSncWFO3Qfuyvr5r7Hhma4kz86wna4eHH0JWzlgbZoEPuCXCK1Vawh4eehvuIzcgAVO ghUQZ/eVzq0zNXqOGL9duy/uXgYCQ48reS/Q/1dUHi5yU8cWqql61pxDpRCofaq87Wmo LDQQ== 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=mbTVLVEwjyagKXL0ZqtVwpJotHPtMu/lSV54IRmaYn2EVWP9fKD06lwjNjZMbJWtuy R0iDaUHXZR/MGN4Tnt+llLk2MzIABKWQKjI8Scm8NtvW31A2tYLnqCnoWuJM7u3p2k83 4HE3XD2bpDb5xoCDwr97N7gRDvFM/4PbQyQI9Z5PckBKO+hosPIB6OgrpQw/ZshYeti8 e8c2djIcBlQpSVMrzIUfDpowo8otwIjb/Rg0EwdbFU/LXzJm3so0QPw7B28IrsQ3Upf9 w0iss6KJLG40qbaU5jwcHp8A2rquT72g5qFR46RURoacUjBNXpA1kfaalUFhMi2qp8s6 TsWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wn7F9wNY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id i5si4330512pli.153.2022.02.21.21.14.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 21:14:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wn7F9wNY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 74B90E0A38; Mon, 21 Feb 2022 20:46:25 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350114AbiBUJ31 (ORCPT + 99 others); Mon, 21 Feb 2022 04:29:27 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:35908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349817AbiBUJVt (ORCPT ); Mon, 21 Feb 2022 04:21:49 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C3E1369C8; Mon, 21 Feb 2022 01:09:07 -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 15C196092A; Mon, 21 Feb 2022 09:09:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF138C340E9; Mon, 21 Feb 2022 09:09:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1645434546; bh=jpZH6xrh9hccXtiZXWyWHqnt+rfjkT9gFkXP6XsvMPw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wn7F9wNY4nqklOp0tkIxLdFI+8xvM7mXK51Z3JaV+H+AHvMpdQsIh2aLKPfuqLOn5 sFdUvSQPG2T2B9IvqV92g+EPI8MDB5bPm6FDv6f8CHxa3LGqHUsOK8cNq4r766BA7K L0dJ/kYw54HSr1i2PLmcOiXfQpICKSifrewdsD7g= 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.15 013/196] mm: dont try to NUMA-migrate COW pages that have other uses Date: Mon, 21 Feb 2022 09:47:25 +0100 Message-Id: <20220221084931.336758063@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220221084930.872957717@linuxfoundation.org> References: <20220221084930.872957717@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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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; /*