Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp6294822pxv; Thu, 29 Jul 2021 10:54:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/zYncgg9u/Mm7/kba50JtRO0vrph/bitoi6AgFVJD3iVaDzooBg5vEzVdl1kIdqSAxDVJ X-Received: by 2002:a5d:9d42:: with SMTP id k2mr867154iok.124.1627581264925; Thu, 29 Jul 2021 10:54:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627581264; cv=none; d=google.com; s=arc-20160816; b=MltajRFi3dX5UzTvmObbrsQnZkJS2lPRKdGf4wDnHVdh0ihVz/fvjHZAMOtGhBfOcg NLIPfTCWjtNNXpCPMd56B2VvaPlpEFbM8NJ6txXxrA4Q7Bzys0OFIxCBIfocY4b1FOJg fdFS7/hSwhcNd9bsd5aSQLJNc7HWmAM1rpPqkfKYG8Cj8Q0UEMDVrDuGMyo4IkYoLWgh KL6sAAaaEpkkmFim+Eve6TE7dtjAs5+SQ1FpfbEa+fxNkg1XSQDO7HW6rr8xJoAZ4MA2 4RlZ4qlbjf12jF/B9p4h+iQ849WRXU2d5kcZ3xUaHBnC49Fus3ca0iUA0XguSXGdBsia fgsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :dkim-signature; bh=LumGgLCeyK4KjVZYvtbb1+LUCYeCqpEP8VhQetdghNU=; b=XKSlO7oumMRQYoEMXUnPInMVxgOSilNAMzx9UG6GaI16RU8CxG3HiqsM13lndwGccx jMRrZtIymgMfVPXOnwWtkxSZqQcxXWVmtUgliUbQvNbvitSouhL33IogO6u5AJGJDUG6 E2WyhtdaGeq1na5VeLLdQ9DHUTKyuzz2Gke0l03WNTSMFHjWt128zXiNcKsGdviHdt4o XrGbLaeSu0LBxOm2P2yVd9THZFrpRaRQJjD8k9F0VVEABZMuddQdrB/0N3KmoJGT/oUc AEEjJX7wQzzZSf67P7fO2zq/jslTDhqSJqf3E26DneG5b5TAk5tRtC9myQyGD6UkBLtS DjKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=wVpaleMo; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s22si4325877iow.33.2021.07.29.10.54.11; Thu, 29 Jul 2021 10:54:24 -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=@google.com header.s=20161025 header.b=wVpaleMo; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229620AbhG2Rw0 (ORCPT + 99 others); Thu, 29 Jul 2021 13:52:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229485AbhG2RwZ (ORCPT ); Thu, 29 Jul 2021 13:52:25 -0400 Received: from mail-qt1-x84a.google.com (mail-qt1-x84a.google.com [IPv6:2607:f8b0:4864:20::84a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 614B7C061765 for ; Thu, 29 Jul 2021 10:52:21 -0700 (PDT) Received: by mail-qt1-x84a.google.com with SMTP id v7-20020ac874870000b029024e8ccfcd07so3076187qtq.11 for ; Thu, 29 Jul 2021 10:52:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=LumGgLCeyK4KjVZYvtbb1+LUCYeCqpEP8VhQetdghNU=; b=wVpaleMoJoJChs6S3PUwQoyOdiErO3+JvkB5ediExtYYrxunHKaeb7c8qAxRaHtabl VSRp3XvD/CJFU0mziZ6tM8hHVZ6RfED3AQP00r2Ub0FgOnHcguxyclUpNXawntmJ5TeV 6Bnt7RQv9VWlF+ipg0lx6MAUntjj49FhRvfjqBwVtBh1HWKyGc9Cgy0OPUtQfCEXxryX QSJjfN/5jTok0O6Us+bl6KsyS/LYBcF5w34M3SjBIyYfkCKZ/bXBCbrdxUTq+rSwMveU GqZmi3ZHPPz94xJ6f8McYts27OivZflLBAXm75nnGDhmziwTF1EkkmrvRm5I5guTzWpT i5sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=LumGgLCeyK4KjVZYvtbb1+LUCYeCqpEP8VhQetdghNU=; b=eL7Idah5TylQPZaMNH90qOmFLUOWOixkkWIvobJnmw4iTxHAPdfJ55728Q4jt0LrQE lohYxVRARgcfTu+c3bOU2qxgPB7qoaH+9d1aQUlxGNmqzzgmYaYEaZkHGsEwrOVtKrsk HE/PlWFNhg6fLmeKH+9Sw8wcOL9D5dQiZRCdIlTOMpscqvhW6L5Y4mE70htpVP+FP15u nLCw90uL/AU5Z4lhmfKqGOhlcXsS3rHEec7NjMTOZmbK/kCA8v3lmv1v1UTFNTH31qdZ dzmocQWcEKiPKNa07OkFPoFOqYSnxlDQAy5s5Yc6/5zo7jPvJyIHysMi8aYuMob2fzFx a9qw== X-Gm-Message-State: AOAM531Djrjt0kJIBmEbYYttwdARmQ+4CHi9fhQGCfmjOkyvc9O/hZUT o/G9SQkkYFEUBCCQKnNRO+XdV86JMwmU X-Received: from luke.lon.corp.google.com ([2a00:79e0:d:210:293a:bc89:7514:5218]) (user=qperret job=sendgmr) by 2002:a0c:e6a4:: with SMTP id j4mr6588994qvn.16.1627581140492; Thu, 29 Jul 2021 10:52:20 -0700 (PDT) Date: Thu, 29 Jul 2021 18:52:13 +0100 Message-Id: <20210729175214.294142-1-qperret@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.32.0.554.ge1b32706d8-goog Subject: [PATCH v2] sched/deadline: Fix sched_getattr() for DL tasks From: Quentin Perret To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , linux-kernel@vger.kernel.org Cc: kernel-team@android.com, Quentin Perret Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In its current state, sched_getattr() can report incorrect sched_flags if called on a deadline task. Firstly, if the reset_on_fork flag is set on a deadline task using sched_setattr() with SCHED_FLAG_RESET_ON_FORK | SCHED_FLAG_KEEP_PARAMS, p->sched_reset_on_fork will be set but __setscheduler() will bail out early without updating the dl_se->flags. Consequently, if sched_getattr is then called on the same task, __getparam_dl() will override kattr.sched_flags with the now out-of-date copy in dl_se->flags and report a stale reset_on_fork value to userspace. And secondly, sched_getattr() currently reports SCHED_FLAG_SUGOV as set if called on a schedutil worker, despite this flag being a kernel-only value that is not exposed in UAPI headers. To fix both of these problems, make sure to only copy the flags that are relevant to sched_deadline to dl_se->flags, and filter them out when reporting them back to userspace. Signed-off-by: Quentin Perret --- v1 can be found here: https://lore.kernel.org/r/20210727101103.2729607-1-qperret@google.com/ Changes since v1: - squashed the two patches together - moved the SCHED_FLAG_SUGOV filtering to __getparam_dl() --- 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 aaacd6cfd42f..358a8a2acfc2 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -2741,7 +2741,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); } @@ -2754,7 +2754,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 & ~SCHED_FLAG_SUGOV; } /* @@ -2851,7 +2852,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 14a41a243f7b..ad3aee63db26 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.32.0.554.ge1b32706d8-goog