Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1227094pxx; Tue, 27 Oct 2020 11:12:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTu8g6Jd71JvCItXNsjlgWrVM0dbdcxUy8BreJLwDU93fBb8qsatiQ13wn+/AQmvPyjXxG X-Received: by 2002:aa7:c7d9:: with SMTP id o25mr3711578eds.318.1603822368746; Tue, 27 Oct 2020 11:12:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603822368; cv=none; d=google.com; s=arc-20160816; b=d94h44GZG503bpaD3QUk1XUUgzYb0VSFMOaXGCoXdBO4HX0NNJ0+546R9ifcFOgQbf R09c6F/5pDPZV/P/5GQehHPG0b3pdMHJ7PL2sjMH53Y34HV3oYPbEV88o2fpZIx6tLPQ 1/M4uMpL6nFpB19YuI5ocQzDo/BlH91INj4hXsPR8SfLi3Qc0kN4QPJURbrvhCVa9806 GYDD8wLfrTxwkg5HPodZn86PMaLZtu7P6JDazrH9e1T7F5/NH6CKHc8h94yxtf2reeei 5crKD1lCOYqUs/ZNzvIFX26imeSuxtbILq4Wdo3ViTHMjgMjr5c6vUYtbUm50mp+HRis T4dw== 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=2xAKoY9hTh+98g77zBvsMPz21prtxQ5nhXqHf/EJUiw=; b=MGSsPKmwVm7NlSJPtp6J8Eyh5Y0LqbpjbwPu1QZ7gvTd6iggsdknCLnZPK4/bCasaO kR9pftG++M6JbQdXiB2rvkYJZKhooOVwNBDGbvV6M7Hmo85Tu+K3Osz2XMlqoNIsWLWs niShatlJQp4WVokztVkFipE61Ws8CJjH6IXqbTtTi8hlSyGwcq8qbNyEP6c6AfoAo7Ym cxGZtJxQI9MvxTzzPPquLDaKbEUNwMfZRolmFH6HpZacpSsJMUkg3GLI28FHxxWpAW03 ZM5PVQBDtwz45O35FCLB804iIFHmuHfYEKzYmT1mU4mW4lMsCLxr2fQjuBmbWSCUsUF7 c9Iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Kh43uoTk; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j10si1640079ejs.577.2020.10.27.11.12.26; Tue, 27 Oct 2020 11:12:48 -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; dkim=pass header.i=@kernel.org header.s=default header.b=Kh43uoTk; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1821542AbgJ0Ron (ORCPT + 99 others); Tue, 27 Oct 2020 13:44:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:57658 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2902147AbgJ0ObC (ORCPT ); Tue, 27 Oct 2020 10:31:02 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D56A220780; Tue, 27 Oct 2020 14:31:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603809061; bh=Q7s2e4JccszcPEZZZ2r/6Nif1WeoarCHcmCBLfoWw14=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Kh43uoTkEMP+VrOSW3rmm5+rK5N8zQvKWdE2i5q7O1HvOhrWs2VgZmx4dfrkyt4Kl LQabyi0bg8CunDrhBkWftrBK6lVtziKBZvnXtugMJzJX6+6HlSrEmFWrzizqZZESIy UalKMHqFPsUbzDsv1Huue4EAMmO7xVMohVu4YEVY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wetp Zhang , Xunlei Pang , "Peter Zijlstra (Intel)" , Jiang Biao , Vincent Guittot , Sasha Levin Subject: [PATCH 5.4 062/408] sched/fair: Fix wrong cpu selecting from isolated domain Date: Tue, 27 Oct 2020 14:50:00 +0100 Message-Id: <20201027135457.942357675@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135455.027547757@linuxfoundation.org> References: <20201027135455.027547757@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xunlei Pang [ Upstream commit df3cb4ea1fb63ff326488efd671ba3c39034255e ] We've met problems that occasionally tasks with full cpumask (e.g. by putting it into a cpuset or setting to full affinity) were migrated to our isolated cpus in production environment. After some analysis, we found that it is due to the current select_idle_smt() not considering the sched_domain mask. Steps to reproduce on my 31-CPU hyperthreads machine: 1. with boot parameter: "isolcpus=domain,2-31" (thread lists: 0,16 and 1,17) 2. cgcreate -g cpu:test; cgexec -g cpu:test "test_threads" 3. some threads will be migrated to the isolated cpu16~17. Fix it by checking the valid domain mask in select_idle_smt(). Fixes: 10e2f1acd010 ("sched/core: Rewrite and improve select_idle_siblings()) Reported-by: Wetp Zhang Signed-off-by: Xunlei Pang Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Jiang Biao Reviewed-by: Vincent Guittot Link: https://lkml.kernel.org/r/1600930127-76857-1-git-send-email-xlpang@linux.alibaba.com Signed-off-by: Sasha Levin --- kernel/sched/fair.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index b02a83ff40687..dddaf61378f62 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -5936,7 +5936,7 @@ static int select_idle_core(struct task_struct *p, struct sched_domain *sd, int /* * Scan the local SMT mask for idle CPUs. */ -static int select_idle_smt(struct task_struct *p, int target) +static int select_idle_smt(struct task_struct *p, struct sched_domain *sd, int target) { int cpu, si_cpu = -1; @@ -5944,7 +5944,8 @@ static int select_idle_smt(struct task_struct *p, int target) return -1; for_each_cpu(cpu, cpu_smt_mask(target)) { - if (!cpumask_test_cpu(cpu, p->cpus_ptr)) + if (!cpumask_test_cpu(cpu, p->cpus_ptr) || + !cpumask_test_cpu(cpu, sched_domain_span(sd))) continue; if (available_idle_cpu(cpu)) return cpu; @@ -5962,7 +5963,7 @@ static inline int select_idle_core(struct task_struct *p, struct sched_domain *s return -1; } -static inline int select_idle_smt(struct task_struct *p, int target) +static inline int select_idle_smt(struct task_struct *p, struct sched_domain *sd, int target) { return -1; } @@ -6072,7 +6073,7 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target) if ((unsigned)i < nr_cpumask_bits) return i; - i = select_idle_smt(p, target); + i = select_idle_smt(p, sd, target); if ((unsigned)i < nr_cpumask_bits) return i; -- 2.25.1