Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1193146ybf; Thu, 27 Feb 2020 06:36:24 -0800 (PST) X-Google-Smtp-Source: APXvYqymVlI3DkQPDs5NsMlcGwCygPnE53pHt4qtsrN78+69UJ/gmQv1kVKfMSJ/iqwIw6Pp3Z+H X-Received: by 2002:a9d:68c8:: with SMTP id i8mr3742314oto.34.1582814184427; Thu, 27 Feb 2020 06:36:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582814184; cv=none; d=google.com; s=arc-20160816; b=Ad6bSdkJ6z/AZTB7uUH4pUmyCkqUiMh57lER83h5V6NTAJ8Z38AEE3Ok3QzTN0w2Dn aUTaQiBI98WgJpPIwFZb2YQ/HrwlW1KeQllh/JAoHVyknMTjK/B/QLMVw+L+KPRF3Wqt exxYhwA4CXrWgwNBKja4sv16eY9FGjJz7JasC66anRpt3CmSeFU2Ez6z9jn+lt/zzOab 7pj/6VRZVI5IA+Ojtg+GDTsHvdwrRJBh3z9Uu3uIaUogXW2rgsl3KCRozMMmEwD6/VWQ FnYTntOywB2ygbAJEDFyQ70kzl47RAkpfiFEYlozwIA0xaMv/G9qEOMfZHJzBn9keKX5 a/HA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:to:from:dkim-signature; bh=0xAEWHTNxn9LX86U18hBbs8SllTc+RoxcyWwqRo+1Ho=; b=p6QzS9rsUOIeI8oinwTQFxe/bAcLdnlJmAadpKbLaAdDcry8zbymxgkxZKe6h/Dmw5 L0nkruUQthqfZLAgvAmuu2Dm5VbVImRQBC8H/KzsrqorbZEI7MK1LRQAeBu1vZ931pj1 cycI6KqEy4/jYO+Uknhgc5X6CASAL1xgV99ukN/n5TyEHAJklpOiqjtNzJg4xMf+Hp59 KKw4bgxkeGPNeiv0FiGVe3nueJQZmvgLy+UOmUzSIvQT/CMPormBaXvPNz8WDApsVChb 5GztY8Vv96cxUWiSgEat89Ewss/5yGdp67VIVSlcZLXVqFlvia6zkN4D8gzv/xrenlwc NE6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SSis0gJk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h128si1362302oif.258.2020.02.27.06.36.12; Thu, 27 Feb 2020 06:36:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SSis0gJk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388641AbgB0OeY (ORCPT + 99 others); Thu, 27 Feb 2020 09:34:24 -0500 Received: from mail.kernel.org ([198.145.29.99]:45304 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388319AbgB0OeU (ORCPT ); Thu, 27 Feb 2020 09:34:20 -0500 Received: from localhost.localdomain (c-98-220-238-81.hsd1.il.comcast.net [98.220.238.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7FE23246BF; Thu, 27 Feb 2020 14:34:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582814060; bh=Sy9jfvG4hbrvYVDo6cy+cJejN6vAL21ZAoPDo/x87JY=; h=From:To:Subject:Date:In-Reply-To:References:In-Reply-To: References:From; b=SSis0gJkRwHfsbIF4u48iRggj1XnwszikkB/T8n3FHmZFGtq1zArY3Av9Zcatin5z QnflyxMYRE8rA0mTDbnvq7FteYAiPcT1aEWGLnGVioAFbc5sR1M+ocrccR20hmL94U FqMRoQawk2jrCkcdoant9DJHJx3ee3rIyk76rOMU= From: zanussi@kernel.org To: LKML , linux-rt-users , Steven Rostedt , Thomas Gleixner , Carsten Emde , John Kacur , Sebastian Andrzej Siewior , Daniel Wagner , Tom Zanussi Subject: [PATCH RT 21/23] sched: migrate_enable: Busy loop until the migration request is completed Date: Thu, 27 Feb 2020 08:33:32 -0600 Message-Id: X-Mailer: git-send-email 2.14.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sebastian Andrzej Siewior v4.14.170-rt75-rc2 stable review patch. If anyone has any objections, please let me know. ----------- [ Upstream commit 140d7f54a5fff02898d2ca9802b39548bf7455f1 ] If user task changes the CPU affinity mask of a running task it will dispatch migration request if the current CPU is no longer allowed. This might happen shortly before a task enters a migrate_disable() section. Upon leaving the migrate_disable() section, the task will notice that the current CPU is no longer allowed and will will dispatch its own migration request to move it off the current CPU. While invoking __schedule() the first migration request will be processed and the task returns on the "new" CPU with "arg.done = 0". Its own migration request will be processed shortly after and will result in memory corruption if the stack memory, designed for request, was used otherwise in the meantime. Spin until the migration request has been processed if it was accepted. Signed-off-by: Sebastian Andrzej Siewior Signed-off-by: Tom Zanussi --- kernel/sched/core.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index e10e3956bb29..f30bb249123b 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -7002,7 +7002,7 @@ void migrate_enable(void) WARN_ON(smp_processor_id() != cpu); if (!is_cpu_allowed(p, cpu)) { - struct migration_arg arg = { p }; + struct migration_arg arg = { .task = p }; struct cpu_stop_work work; struct rq_flags rf; @@ -7015,7 +7015,10 @@ void migrate_enable(void) &arg, &work); tlb_migrate_finish(p->mm); __schedule(true); - WARN_ON_ONCE(!arg.done && !work.disabled); + if (!work.disabled) { + while (!arg.done) + cpu_relax(); + } } out: -- 2.14.1