Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp5868306pxv; Wed, 7 Jul 2021 13:42:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy87wSTElI+XizREFdlGysLtkJ6tga8BcUkoFhES0r7UmxPyd85PEz9IGAGtwprHHV33EBy X-Received: by 2002:a92:a30d:: with SMTP id a13mr20166546ili.236.1625690548049; Wed, 07 Jul 2021 13:42:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625690548; cv=none; d=google.com; s=arc-20160816; b=qHbuhhxwIINfGw08pgxCmO+nk/yNbbMpUbNz8NGP/sflWIgcYMbrLPMBRsty9priNk 3gWv5y8OpbONzOxomFKqkDq1Y7Sb9ILAcDpsP9DsckOuLCxhQpFUt3xQUTTyOVaORHRJ K+auILdxhNv1/OSV8xk9nX9tGsPhpAEBqmCvzyBfV2KHdI/zSt83wOm1iV1e+J8oeqZt +xZiLdyksH9C6TKyRQSnJYMFmuoPsclt9ebfVAc2I0ik65An3IuIzyq2E4xAfCT+qrqU OMH6R8HXxVPjyr+DuwvCkfGtg/6pflYK90fRwa9WICrHqb6LU+7+inzdswLxnRBbM+tk ausA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=Q4SO5ZfrTWxlwKe3MYbD+wDiZHgLaanRMH/JOhXsvA8=; b=HPHswbZEf40n1jE9OBogrK7gNYlzOArjeDGDYt49T3oC1KEE/jAYSotilo03QHbic9 DydWylL18GxUjKElgxgA2K2jRc7nLefvEEdHfxHDoGefyeDbs6eVssXRIhammRLkGLuP RVJZmfE6TxU71EQJSdmexlIcrJUMmp4+hy3AiRZpqV9cjzWvngwPw0xzAKLo9C5CrzJn dSo9kQ1E/B0mFt0sZggSEjln12zcwL7G18ao05OHor3vmYoUtfiCl/bQOSCOUYgEJbVK bPEVVAf3hw8njs2BlwufPWnQBN3gV1UNMu4mJWZKRM5vV2Jhwo2lYU7RZh2Ih+sURGR/ P+Aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Jb6d5xUy; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n17si6559826jam.90.2021.07.07.13.42.14; Wed, 07 Jul 2021 13:42:28 -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=@redhat.com header.s=mimecast20190719 header.b=Jb6d5xUy; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230525AbhGGTHv (ORCPT + 99 others); Wed, 7 Jul 2021 15:07:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:40238 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230500AbhGGTHv (ORCPT ); Wed, 7 Jul 2021 15:07:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625684709; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Q4SO5ZfrTWxlwKe3MYbD+wDiZHgLaanRMH/JOhXsvA8=; b=Jb6d5xUy1W2QFFBwdyWAmk7h6by845oWA3YuGvrofLawyafhgUl0EiOZR92PtMcyAbXBgi vB0FsdB85qxuy7HdB7ms/56iUslU7NZ1i9EZ6SubRKq9F68HR6xfVXt9n0rSX1g42DcVW+ lKejUYT3Du2ziulhYv/DAM7TofbwC1I= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-340-wOkl9LZTOaaT6-PggZHJgA-1; Wed, 07 Jul 2021 15:05:08 -0400 X-MC-Unique: wOkl9LZTOaaT6-PggZHJgA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0925556B43; Wed, 7 Jul 2021 19:05:07 +0000 (UTC) Received: from lorien.usersys.redhat.com (ovpn-116-12.rdu2.redhat.com [10.10.116.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 472A760843; Wed, 7 Jul 2021 19:04:58 +0000 (UTC) From: Phil Auld To: linux-kernel Cc: Peter Zijlstra , Waiman Long , Ingo Molnar , Juri Lelli , Vincent Guittot , stable@vger.kernel.org, Phil Auld Subject: [PATCH] sched: Fix nr_uninterruptible race causing increasing load average Date: Wed, 7 Jul 2021 15:04:57 -0400 Message-Id: <20210707190457.60521-1-pauld@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On systems with weaker memory ordering (e.g. power) commit dbfb089d360b ("sched: Fix loadavg accounting race") causes increasing values of load average (via rq->calc_load_active and calc_load_tasks) due to the wakeup CPU not always seeing the write to task->sched_contributes_to_load in __schedule(). Missing that we fail to decrement nr_uninterruptible when waking up a task which incremented nr_uninterruptible when it slept. The rq->lock serialization is insufficient across different rq->locks. Add smp_wmb() to schedule and smp_rmb() before the read in ttwu_do_activate(). Fixes: dbfb089d360b ("sched: Fix loadavg accounting race") Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Juri Lelli Cc: Vincent Guittot Cc: Waiman Long Cc: Signed-off-by: Phil Auld --- kernel/sched/core.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 4ca80df205ce..ced7074716eb 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -2992,6 +2992,8 @@ ttwu_do_activate(struct rq *rq, struct task_struct *p, int wake_flags, lockdep_assert_held(&rq->lock); + /* Pairs with smp_wmb in __schedule() */ + smp_rmb(); if (p->sched_contributes_to_load) rq->nr_uninterruptible--; @@ -5084,6 +5086,11 @@ static void __sched notrace __schedule(bool preempt) !(prev_state & TASK_NOLOAD) && !(prev->flags & PF_FROZEN); + /* + * Make sure the previous write is ordered before p->on_rq etc so + * that it is visible to other cpus in the wakeup path (ttwu_do_activate()). + */ + smp_wmb(); if (prev->sched_contributes_to_load) rq->nr_uninterruptible++; -- 2.18.0