From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 76B7C606A31E for ; Fri, 30 Oct 2026 03:24:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=r8STOhCd; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=sFWn6Osd DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=YxF7dRKdKAp6T/NOw/hryWAVYb3GZKlSovGXpa5oCY8=; b=r8STOhCdMLu9yu XvEcE0Ruuc4o/iqsDYb0HAGLfXtySwwnKNAgC/DEsAh569g8peDSruw7LMDNULGSiQgUxtWa+2ChV 08Pjq9Q5tPutVQXrMBc7dEsKk1noEmUUOLaQIXH85Pqk7XeyLe+sN8BBHQEpEuEyzvaqrDCJe0Ndv KfzxrOoX6Nluy/NSLGaySJjIi7dTMMKDGSnhjyfrAESYDCLgmRd+bwS/Hd47RpzJ1qvdRKgLVbQMI gDDiV3Uetw+c1GkW80vbfVTu9gv4RsfuFAmcNWqoqfO2ndn0VKCFY/ba6tutPbliCFNPnEFXl7Nqh 52IDmg372Qm22PugUigQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xMdEP-0000000Aj9v-2BGL; Fri, 30 Oct 2026 03:24:41 +0000 Received: from out-161.mta1.migadu.com ([95.215.58.161] helo=mta1.migadu.com) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xMdEM-0000000Aj9N-0bID for kexec@lists.infradead.org; Fri, 30 Oct 2026 03:24:40 +0000 X-Envelope-To: kexec@lists.infradead.org DKIM-Signature: a=rsa-sha256; bh=K9e2xpCltZ0luCSKJ76+rRB5TbBjqG8Rs7tkxWAziAc=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1793330674; v=1; x=1793935474; b=sFWn6Osd3p26eREcmcIASru+spScdxjMfW23b0Y2POx0A7cPjdRAZnOrHq+XGzSQm8O8znSL GcPW+KYbC/rayHgTcZsEHJo0uyjZtTCnQEGFm/LVMX+PMJM2sOtnbK4b1ngvJXY84rWZ79OpEq2 myhFIaTzDDfiCZo6MKBT4eIY= X-Envelope-To: kexec@lists.infradead.org Received: by mta10.migadu.com with ESMTPS id 13ff5ce3ac3bfaeb; Fri, 30 Oct 2026 03:24:34 +0000 X-Mizu-Trace-ID: 13ff5ce3ac3bfaeb X-Migadu-Flow: FLOW_OUT From: xu.xin@linux.dev To: david@kernel.org Cc: akpm@linux-foundation.org, aneesh.kumar@kernel.org, apopple@nvidia.com, axelrasmussen@google.com, baohua@kernel.org, baolin.wang@linux.alibaba.com, baoquan.he@linux.dev, chengming.zhou@linux.dev, chrisl@kernel.org, dev.jain@arm.com, gourry@gourry.net, hannes@cmpxchg.org, harry@kernel.org, hughd@google.com, jack@suse.cz, jannh@google.com, jgg@ziepe.ca, jhubbard@nvidia.com, josef@toxicpanda.com, joshua.hahnjy@gmail.com, kas@kernel.org, kasong@tencent.com, kees@kernel.org, kexec@lists.infradead.org, lance.yang@linux.dev, liam@infradead.org, linux-arch@vger.kernel.org, linux-cxl@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, ljs@kernel.org, matthew.brost@intel.com, mhocko@kernel.org, mhocko@suse.com, minchan@kernel.org, muchun.song@linux.dev, nico.pache@linux.dev, nphamcs@gmail.com, npiggin@gmail.com, osalvador@suse.de, pasha.tatashin@soleen.com, peterx@redhat.com, peterz@infradead.org, pfalcato@suse.de, pratyush@kernel.org, qi.zheng@linux.dev, rakie.kim@sk.com, riel@surriel.com, rppt@kernel.org, ryan.roberts@arm.com, shakeel.butt@linux.dev, shikemeng@huaweicloud.com, stable@vger.kernel.org, surenb@google.com, usama.arif@linux.dev, vbabka@kernel.org, weixugc@google.com, will@kernel.org, willy@infradead.org, xu.xin@linux.dev, ying.huang@linux.alibaba.com, youngjun.park@lge.com, yuanchu@google.com, ziy@nvidia.com Subject: [PATCH 38/46] mm/ksm: reset the unstable trees of all nodes Date: Fri, 30 Oct 2026 11:24:09 +0800 Message-Id: <20261030032409.127393-1-xu.xin@linux.dev> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261027-fixes_core-v1-38-6f74bec9a5bb@kernel.org> References: <20261027-fixes_core-v1-38-6f74bec9a5bb@kernel.org> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261029_202438_771714_B281DF5B X-CRM114-Status: GOOD ( 20.44 ) X-Spam-Score: -2.8 (--) X-BeenThere: kexec@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kexec" X-Spam-Status: No, score=-18.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 > > Let's fix it by tracking in ksm_nr_node_ids the actual number of > allocated tree roots. > > remove_all_stable_nodes() and ksm_check_stable_tree() will now scan > more tree roots (skipping the empty ones), which is harmless. > > Fixes: ef53d16cded7 ("ksm: allocate roots when needed") > Cc: stable@vger.kernel.org > Reported-by: Josef Bacik > Signed-off-by: David Hildenbrand (Arm) > --- > mm/ksm.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/mm/ksm.c b/mm/ksm.c > index dbfb8f98b1892..9c51925825cbf 100644 > --- a/mm/ksm.c > +++ b/mm/ksm.c > @@ -475,6 +475,7 @@ static void advisor_stop_scan(void) > #ifdef CONFIG_NUMA > /* Zeroed when merging across nodes is not allowed */ > static unsigned int ksm_merge_across_nodes = 1; > +/* Number of allocated stable and unstable tree roots. */ > static int ksm_nr_node_ids = 1; > #else > #define ksm_merge_across_nodes 1U > @@ -3636,14 +3637,13 @@ static ssize_t merge_across_nodes_store(struct kobject *kobj, > else { > root_stable_tree = buf; > root_unstable_tree = buf + nr_node_ids; > + ksm_nr_node_ids = nr_node_ids; > /* Stable tree is empty but not the unstable */ > root_unstable_tree[0] = one_unstable_tree[0]; > } > } > - if (!err) { > + if (!err) > ksm_merge_across_nodes = knob; > - ksm_nr_node_ids = knob ? 1 : nr_node_ids; > - } > } > mutex_unlock(&ksm_thread_mutex); > > > -- > 2.43.0 Looks correct as far as it goes, but I think it is not quite sufficient on its own. The documentation requires that merge_across_nodes can only be changed when there are no KSM shared pages in the system, but merge_across_nodes_store() does not enforce this at the sysfs level. Should we also reject writes while ksmd is merging? At minimum: + if (ksm_run & KSM_RUN_MERGE) + return -EBUSY; Ideally, we should also check that ksm_pages_shared is zero, since KSM_RUN_STOP (0) does not guarantee that all pages have been unmerged. That would make the interface match the documented sequence and close the remaining race window.