Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp388604lqt; Mon, 18 Mar 2024 10:36:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXk4YdjILognfmtx1J2oBEAWjAaAa2gSJFbCSMkz2xiPB8nB4vx7T5Y7pEMNTq+UW/P0qnQQtnEBb8QB6EvCYh5TckfgiRr6SgKYYrvXA== X-Google-Smtp-Source: AGHT+IENqCIkHz7dlMOV3bKiRzKtG3/D4lGcavSLjB61wpmAqWStXzHLM+EZgPMy12fKThNEGOvM X-Received: by 2002:a05:6a00:1399:b0:6e6:ff89:1c18 with SMTP id t25-20020a056a00139900b006e6ff891c18mr11197303pfg.1.1710783400746; Mon, 18 Mar 2024 10:36:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710783400; cv=pass; d=google.com; s=arc-20160816; b=m159EpqjBYOYdRW0wlrT7s6wO5AspjoWT+5t+PTvO1F31MqXcnTUkHPF3M8Ch5gDmb byatXmLBJvQawCpGX1fyY1UBQaOTQSEnLms0Be8vhwrcxtQnixR20RCaY3pITWw3cjUH cqtrp7cgl6JFykL6p6iRMnRgrCPOCUQkxAGgw1CgJOvOTmqh6aAmwov0pRCOPfHG89ZP Refe5q2cIOu1GqXOSlWqPEkjeILJS7iDY8actZyAuYg1GZvd0SYNgQ6Yx6ghRvrX40yS hIJJ5rmOBIk9pezhuQlpyuiPWxj5yBwRM/3dtz9Q86Nyc+aYM9NIYG4l7iETCEvaG6Of X5Wg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:references:in-reply-to:subject:cc:to:from :dkim-signature; bh=kd3/KuROcegeJ4IEXQZcY+p0ull0SaScgtMChZmBUjY=; fh=U0V7xZd3fBhMqMilK2O1auxz9QV5a0gxNgstbHSjk9A=; b=g8Q+9XEWpqJGCFpZr4wEiVF0gCxpYw5VCWmrie4a0VH/RwiUD6dD/6o7oVeTRq/916 Y8dY7H+Wj1NlHHjezYVyuz+hiYrmLH7yycB+qio5MNhL9ze9YN1ts6vq9Ldko8kqSY72 BdP0JobJlP0IjV2R0r7IsjKYPNTtSa2kXnLieBVKJxQ92Ozi7tL4w5BptomiQVYcvI53 SmELnGxFZDy9EDfiTLqOxMywOSfiFkaPuRMW9OBpkB2RmaY2kvrEP/3IN2t/lmnvK4Eg 8chkm08iBrOaNGiRKU7sZYeVrADrBdw1vsU614JCFLiJcJJU2NJzs+2XngcYvQpgUjG0 mdxA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=iD7p+ozw; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-106465-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-106465-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id w21-20020a63fb55000000b005e8428fe57dsi3060688pgj.454.2024.03.18.10.36.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 10:36:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-106465-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=iD7p+ozw; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-106465-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-106465-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 68054281463 for ; Mon, 18 Mar 2024 17:36:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 91FA057874; Mon, 18 Mar 2024 17:34:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="iD7p+ozw" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D463B54F9C for ; Mon, 18 Mar 2024 17:34:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710783290; cv=none; b=DL1paoFIbOvFCKURaV0vUc0iOJrl234NuK+5Xq27ANXtn1IwqWo+rtpFItmYHhStDtwCm8YqLndZV3a2nPEQ8/+sk/nshF9Fl02YlB/LeD+cl2X53fKxdswKytxHUJexvlq3uS42NfumLmOMXSGsFc5ciJ2H/A7Appp+eNdiQ84= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710783290; c=relaxed/simple; bh=3iaop3a58uHKADlQcfRI1jJ8IYIC7oQNRC98DXDnUV0=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=IgE5WMOV0j7zRIxR0R84ngqsmjlG/eTu7y4l5MzYSQ2ZTZEB167JbxwvzZFdTCyIbQLc5JYpnBDn13m81vbDOXfOA8g27RssWQ3lHrdVnDF8nC6du/n/SppSd65Nc99yWokHU2Mi3wzEh/BqGJ/8x5ZEBqg9QYgoJyYZpeqbx/Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=iD7p+ozw; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710783287; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=kd3/KuROcegeJ4IEXQZcY+p0ull0SaScgtMChZmBUjY=; b=iD7p+ozw+I1v+5OGuf5uXcF8CgBd2rTkyo8ssKx83NSC1QVP2GJ5DzrmQz/l59hEgiYzLm EtcqdDKnfX4+78LDM5iqHuC2m+MVQtxN03S94eJLviPJJsy7Lc88KJXiIAzR+g2uq79DJ3 Kgo7defGhCrPFV1HkArff8HB64vdM0o= Received: from mail-oi1-f198.google.com (mail-oi1-f198.google.com [209.85.167.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-50-JIk4lx9EMmKRb_xWp1NCGQ-1; Mon, 18 Mar 2024 13:34:44 -0400 X-MC-Unique: JIk4lx9EMmKRb_xWp1NCGQ-1 Received: by mail-oi1-f198.google.com with SMTP id 5614622812f47-3c385de08aeso1600656b6e.1 for ; Mon, 18 Mar 2024 10:34:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710783282; x=1711388082; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=kd3/KuROcegeJ4IEXQZcY+p0ull0SaScgtMChZmBUjY=; b=OpUxw0P2hm51lv0RMzYQyrbZDr4KNT+zQ+mR4w2842j8vXUEeQhaQ9b1wvaVSo7sSv eB7YcDSyBietmjw3I3Ll5Li00Ob7ByA0NIx0CzsttHq8O+Xwnd2GBEgOf53viKXW2PqL 1cmXZDyq+Vw5TEjP5nYuUfQi7M0NK88FJKj9CFCy8jkvp1Al8vE7NJL0DJxM8qjH5FXl tXkrBA3KZ4cazTtsG1BoJN9ZwPqrNR20nLcA9rdFMDOKQgiKulZew8TpFLuhtkinXqit tplBJ1rdZktbHdNmJarB/tWQ7RT/dou3zNMV1dDCNwvASIVaH95NOTFEcq5nM1xU6WC3 DG3g== X-Forwarded-Encrypted: i=1; AJvYcCXfBMbQH4ibSisaxfFbXHxPGaUw6Cwkn6SmF0VYnbO68G4m/tKAOhI25g56zhyh1StQUpHd2mxiMEVU6Ke+3+nXi+G7yCz+0aCwEE8W X-Gm-Message-State: AOJu0YwEFudywxmKKBLxKDzrH7sggRXR06tmHaP5iw7ZbX1tae6qe527 QuChAHjAVd8woRsP5y4zuWAAikNwJ/1Jl6Gsam1A7VrU85bCaerJ9wWFPrFDnsdFyoKSi+QZE7g tL4xWFz0qwVLr7+DZX3RbmmvYuJCngGuxsIaPwSXIKF+hYTcITASdYm19ezqv0zH6RTH48EGYoe JKATv4o/T2v+Y5YMGGmSDnmzdm1gKU/e4X1g9AK2jxkhBRSg== X-Received: by 2002:a05:6808:e85:b0:3c2:52b5:23ab with SMTP id k5-20020a0568080e8500b003c252b523abmr15636593oil.50.1710783282411; Mon, 18 Mar 2024 10:34:42 -0700 (PDT) X-Received: by 2002:a05:6808:e85:b0:3c2:52b5:23ab with SMTP id k5-20020a0568080e8500b003c252b523abmr15636557oil.50.1710783282120; Mon, 18 Mar 2024 10:34:42 -0700 (PDT) Received: from vschneid-thinkpadt14sgen2i.remote.csb (213-44-141-166.abo.bbox.fr. [213.44.141.166]) by smtp.gmail.com with ESMTPSA id gg8-20020a056214252800b00690befbe5a5sm5514612qvb.74.2024.03.18.10.34.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 10:34:41 -0700 (PDT) From: Valentin Schneider To: Daniel Vacek , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira Cc: Daniel Vacek , stable@vger.kernel.org, Bill Peters , Ingo Molnar , linux-kernel@vger.kernel.org Subject: Re: [PATCH] sched/core: fix affine_move_task failure case In-Reply-To: <20240318111750.3097906-1-neelx@redhat.com> References: <20240318111750.3097906-1-neelx@redhat.com> Date: Mon, 18 Mar 2024 18:34:37 +0100 Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain On 18/03/24 12:17, Daniel Vacek wrote: > Bill Peters reported CPU hangs while offlining/onlining CPUs on s390. > > Analyzing the vmcore data shows `stop_one_cpu_nowait()` in `affine_move_task()` > can fail when racing with off-/on-lining resulting in a deadlock waiting for > the pending migration stop work completion which is never done. > > Fix this by correctly handling such a condition. > IIUC the problem is that the dest_cpu and its stopper thread can be taken down by take_cpu_down(), and affine_move_task() currently isn't aware of that. I thought we had tested this vs hotplug, but oh well... > Fixes: 9e81889c7648 ("sched: Fix affine_move_task() self-concurrency") > Cc: stable@vger.kernel.org > Reported-by: Bill Peters > Tested-by: Bill Peters > Signed-off-by: Daniel Vacek > --- > kernel/sched/core.c | 13 +++++++++++-- > 1 file changed, 11 insertions(+), 2 deletions(-) > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index 9116bcc903467..d0ff5c611a1c8 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -3069,8 +3069,17 @@ static int affine_move_task(struct rq *rq, struct task_struct *p, struct rq_flag > preempt_disable(); > task_rq_unlock(rq, p, rf); > if (!stop_pending) { > - stop_one_cpu_nowait(cpu_of(rq), migration_cpu_stop, > - &pending->arg, &pending->stop_work); > + stop_pending = > + stop_one_cpu_nowait(cpu_of(rq), migration_cpu_stop, > + &pending->arg, &pending->stop_work); > + > + if (!stop_pending) { > + rq = task_rq_lock(p, rf); > + pending->stop_pending = false; > + p->migration_pending = NULL; > + task_rq_unlock(rq, p, rf); > + complete_all(&pending->done); > + } This can leave the task @p on a now-illegal CPU; consider a task affined to CPUs 0-1, migrate_disable(); then affined to CPUs 2-3, then in migrate_enable() the dest_cpu is chosen as 3 but that's racing with it being brought down. The stop_one_cpu_nowait() fails, and we leave the task on CPUs 0-1. Issuing a redo of affine_move_task() with a different dest_cpu doesn't sound great, and while very unlikely that doesn't have forward progress guarantees. Unfortunately we can't hold the hotplug lock during the affinity change of migrate_enable(), as migrate_enable() isn't allowed to block. Now, the CPU selection in __set_cpus_allowed_ptr_locked() that is passed down to affine_move_task() relies on the active mask, which itself is cleared in sched_cpu_deactivate() and is followed by a synchronize_rcu(). What if we made the affinity change of migrate_enable() an RCU read-side section? Then if a CPU X is observed as active in migrate_enable()->__set_cpus_allowed_ptr_locked() , then its' hotplug state cannot go lower than CPUHP_AP_ACTIVE until the task is migrated away. Something like the below. Thoughts? --- diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 929fce69f555e..c6d128711d1a9 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -2450,8 +2450,11 @@ void migrate_enable(void) * __set_cpus_allowed_ptr(SCA_MIGRATE_ENABLE) doesn't schedule(). */ guard(preempt)(); - if (p->cpus_ptr != &p->cpus_mask) + if (p->cpus_ptr != &p->cpus_mask) { + guard(rcu)(); __set_cpus_allowed_ptr(p, &ac); + } + /* * Mustn't clear migration_disabled() until cpus_ptr points back at the * regular cpus_mask, otherwise things that race (eg.