Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp93491pxb; Mon, 13 Sep 2021 13:54:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwCoI/JE+A1blp57fNr6cVwNlJCLEYrXe5O7WXLMPfpcxFN44tOm89g3hW2NUOjldFa4ci3 X-Received: by 2002:a17:906:c249:: with SMTP id bl9mr14874388ejb.225.1631566458559; Mon, 13 Sep 2021 13:54:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631566458; cv=none; d=google.com; s=arc-20160816; b=xAFuw4Yuc78ozyMk98CNuug4sD0g69psJjbp/Dd6li58J/nv0fMWBRYcxGAVTL1jlN lb4ogYpf4ThxmryYhixf5OoB5moslUuSYiS601926QIppv4eQpmJQTm8Cf4XosQ8Bl+A 9iXucDgQYY6HOTo096XRYhMzBH+m6PHGwDqZ/p2QUv2QuYPwK/L8kGsbAayuSZFTnr59 ouvzD3ugFJxPbs8hNMG2yW3PiK/5kWCpoKaZDk8YKuf6IyKd4fqJSJor3BCCNIYMSUUw GS7Qy0zBOqZNg3XUzKBvLYmGa3GaAcXMuRq+wdWnFacVGi8nB9bJ5LODEDzCq3WxL6Gz pvig== 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=d8QDwBUBB061QDC9TnDBKY5xYLvZWbjvVNkBpIqf8Ko=; b=MXQUxiEsMYlizkNp5448ea8cFLWHmn7rAfPhiO2pFXWq1i261D/97iPJQ7wXTlximc EZSdvfyT/QK6nEh3zfhsVMGKaHlHUIeeoPvc8q9wN41B9A11zW4ril541g+/OMwfARLw 3wImzT8PUA1OlgQ3SH98HJRcQEPJJW9XRYWA/rhzHM8gONyYmmBbEFYXUXkrXtOH9ayc 2UoMSRL4I7Tz6QAKq9qJYdmEmGkLvSi6zCVBGW6TVQ5a8fsc/IzOo7zZkNeBhmu6wL1H yCJIN9PqAtqf+61jivIzFRKPSTuN1d+2EBKfZ+GtE2HfooMDUfTENyqc5LJzYnvZnHy+ Z76A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AzLfVfSZ; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gv23si8410263ejc.249.2021.09.13.13.53.54; Mon, 13 Sep 2021 13:54:18 -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=@linuxfoundation.org header.s=korg header.b=AzLfVfSZ; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245247AbhIMNy2 (ORCPT + 99 others); Mon, 13 Sep 2021 09:54:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:34740 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244860AbhIMNuz (ORCPT ); Mon, 13 Sep 2021 09:50:55 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 48C356139D; Mon, 13 Sep 2021 13:33:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631540029; bh=Fe/tj3mr3pFosyjUyABBpAvM07r/w+VRHCrXGriScD8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AzLfVfSZY2CVAcstrDVCkABwVObliAsBm3jY7vjgIl6jXzxUZyBTMoP+kUQY//gGX mX0aE17jNXx85Q/ML4jle/GC3jEnOhO5iAnWCwTPnLjYDkfyO7tmDpkp+mg7OG0KnP mnIHqDdohVs4ZIkU5bOt1RU7WJTpRZ8EXyefdxcE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Quentin Perret , "Peter Zijlstra (Intel)" , Sasha Levin Subject: [PATCH 5.13 005/300] sched/deadline: Fix reset_on_fork reporting of DL tasks Date: Mon, 13 Sep 2021 15:11:06 +0200 Message-Id: <20210913131109.456534413@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131109.253835823@linuxfoundation.org> References: <20210913131109.253835823@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: Quentin Perret [ Upstream commit f95091536f78971b269ec321b057b8d630b0ad8a ] It is possible for sched_getattr() to incorrectly report the state of the reset_on_fork flag when called on a deadline task. Indeed, if the flag was set on a deadline task using sched_setattr() with flags (SCHED_FLAG_RESET_ON_FORK | SCHED_FLAG_KEEP_PARAMS), then p->sched_reset_on_fork will be set, but __setscheduler() will bail out early, which means that the dl_se->flags will not get updated by __setscheduler_params()->__setparam_dl(). Consequently, if sched_getattr() is then called on the task, __getparam_dl() will override kattr.sched_flags with the now out-of-date copy in dl_se->flags and report the stale value to userspace. To fix this, make sure to only copy the flags that are relevant to sched_deadline to and from the dl_se->flags field. Signed-off-by: Quentin Perret Signed-off-by: Peter Zijlstra (Intel) Link: https://lore.kernel.org/r/20210727101103.2729607-2-qperret@google.com Signed-off-by: Sasha Levin --- kernel/sched/deadline.c | 7 ++++--- kernel/sched/sched.h | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c index 2f9964b467e0..7ddb1202794f 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -2729,7 +2729,7 @@ void __setparam_dl(struct task_struct *p, const struct sched_attr *attr) dl_se->dl_runtime = attr->sched_runtime; dl_se->dl_deadline = attr->sched_deadline; dl_se->dl_period = attr->sched_period ?: dl_se->dl_deadline; - dl_se->flags = attr->sched_flags; + dl_se->flags = attr->sched_flags & SCHED_DL_FLAGS; dl_se->dl_bw = to_ratio(dl_se->dl_period, dl_se->dl_runtime); dl_se->dl_density = to_ratio(dl_se->dl_deadline, dl_se->dl_runtime); } @@ -2742,7 +2742,8 @@ void __getparam_dl(struct task_struct *p, struct sched_attr *attr) attr->sched_runtime = dl_se->dl_runtime; attr->sched_deadline = dl_se->dl_deadline; attr->sched_period = dl_se->dl_period; - attr->sched_flags = dl_se->flags; + attr->sched_flags &= ~SCHED_DL_FLAGS; + attr->sched_flags |= dl_se->flags; } /* @@ -2839,7 +2840,7 @@ bool dl_param_changed(struct task_struct *p, const struct sched_attr *attr) if (dl_se->dl_runtime != attr->sched_runtime || dl_se->dl_deadline != attr->sched_deadline || dl_se->dl_period != attr->sched_period || - dl_se->flags != attr->sched_flags) + dl_se->flags != (attr->sched_flags & SCHED_DL_FLAGS)) return true; return false; diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index f2bc99ca01e5..9aa157c20722 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -227,6 +227,8 @@ static inline void update_avg(u64 *avg, u64 sample) */ #define SCHED_FLAG_SUGOV 0x10000000 +#define SCHED_DL_FLAGS (SCHED_FLAG_RECLAIM | SCHED_FLAG_DL_OVERRUN | SCHED_FLAG_SUGOV) + static inline bool dl_entity_is_special(struct sched_dl_entity *dl_se) { #ifdef CONFIG_CPU_FREQ_GOV_SCHEDUTIL -- 2.30.2