From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.9 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FSL_HELO_FAKE, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13560C388F9 for ; Thu, 19 Nov 2020 09:47:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AC313246E4 for ; Thu, 19 Nov 2020 09:47:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="boKOL+16" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726775AbgKSJru (ORCPT ); Thu, 19 Nov 2020 04:47:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726287AbgKSJru (ORCPT ); Thu, 19 Nov 2020 04:47:50 -0500 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB717C0613CF for ; Thu, 19 Nov 2020 01:47:49 -0800 (PST) Received: by mail-wr1-x441.google.com with SMTP id p8so5738390wrx.5 for ; Thu, 19 Nov 2020 01:47:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=g38xN0FDkwhpZzEhM271vqmkWxD69SkDmYogp+3razQ=; b=boKOL+16LzadIMhdXR656SedOKYpIvGLcI2AlaTC8Cq/lTr1baf1u6HUNT0bASYkOa oAu7td6myhRWROuJEHaBafytCXTqNsIGaFKD6r2Mct8z14nDy99MyyDHmv5KE67UW7IG llq1B0K5zfJc6KCxhEQnfYFzwXSeZkQ0S4rtHHbNkXkO6fz8U7dNbxpe1pRGExnF+28q rC2hPzCMf0ru3+/G4fUey+Mrm4v0ZgLHqaQfKxA5DTv+WEtv4CugZoqnv4a8FkHi/Dz/ 2o5xBJeoBZjGCYxP8UyZomtfMeQHNYoqI+RKO57kxdbpaKGNkl/mV2xQypznsLu1wTx2 rnyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=g38xN0FDkwhpZzEhM271vqmkWxD69SkDmYogp+3razQ=; b=udJwqPi9zhvCWoPIEDhdiUVGxaLvhYqG0nc8jTwv3gHLWTLXorqrTwgDqDAERTXbz9 iOJaRjL6rDwah/bgIOCkA+YmqiB0kvVSYhfk0xZPtU8kdVIjcrpoYovgepHlauBFtrtS 380CY8/xWs2T6K7GFVNDGkCLmHw5qKWeC982KM3J/1E574QsKovntkHweSsH5akzl9n0 i0FtSinwI/IhSKwiE+ewWnRk+Lwpqeh2RcQgR/K9QVBOer731XrEcqBwzqubDnSAGVjL ndW8pf+89QCQOVXmOWL/op6pwmmPu1WgDxj7tlLnMMnTD5KTLeDdUYNopcvMDynmasf9 4fAw== X-Gm-Message-State: AOAM530UCck9Uhzcc48rgA9ce+y7v2bt7xvlCKlqm+LmcfnEh9IOHVWk w7y6EM8rImtwFLvbt1hJ/C+35A== X-Google-Smtp-Source: ABdhPJzSkfKT2wUMTd6J8oqmowCmaCTnckpBFf352uxLmwWqYQq4slZX+ptNmWR0V342nxkaJPvwNg== X-Received: by 2002:a5d:4612:: with SMTP id t18mr9098818wrq.401.1605779268509; Thu, 19 Nov 2020 01:47:48 -0800 (PST) Received: from google.com ([2a00:79e0:d:210:f693:9fff:fef4:a7ef]) by smtp.gmail.com with ESMTPSA id h20sm8303072wmb.29.2020.11.19.01.47.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 01:47:48 -0800 (PST) Date: Thu, 19 Nov 2020 09:47:44 +0000 From: Quentin Perret To: Will Deacon Cc: linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, Catalin Marinas , Marc Zyngier , Greg Kroah-Hartman , Peter Zijlstra , Morten Rasmussen , Qais Yousef , Suren Baghdasaryan , Tejun Heo , Li Zefan , Johannes Weiner , Ingo Molnar , Juri Lelli , Vincent Guittot , kernel-team@android.com Subject: Re: [PATCH v3 11/14] sched: Reject CPU affinity changes based on arch_cpu_allowed_mask() Message-ID: <20201119094744.GE2416649@google.com> References: <20201113093720.21106-1-will@kernel.org> <20201113093720.21106-12-will@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201113093720.21106-12-will@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Friday 13 Nov 2020 at 09:37:16 (+0000), Will Deacon wrote: > Reject explicit requests to change the affinity mask of a task via > set_cpus_allowed_ptr() if the requested mask is not a subset of the > mask returned by arch_cpu_allowed_mask(). This ensures that the > 'cpus_mask' for a given task cannot contain CPUs which are incapable of > executing it, except in cases where the affinity is forced. > > Signed-off-by: Will Deacon > --- > kernel/sched/core.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index 8df38ebfe769..13bdb2ae4d3f 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -1877,6 +1877,7 @@ static int __set_cpus_allowed_ptr_locked(struct task_struct *p, > struct rq_flags *rf) > { > const struct cpumask *cpu_valid_mask = cpu_active_mask; > + const struct cpumask *cpu_allowed_mask = arch_cpu_allowed_mask(p); > unsigned int dest_cpu; > int ret = 0; > > @@ -1887,6 +1888,9 @@ static int __set_cpus_allowed_ptr_locked(struct task_struct *p, > * Kernel threads are allowed on online && !active CPUs > */ > cpu_valid_mask = cpu_online_mask; > + } else if (!cpumask_subset(new_mask, cpu_allowed_mask)) { > + ret = -EINVAL; > + goto out; So, IIUC, this should make the sched_setaffinity() syscall fail and return -EINVAL to userspace if it tries to put 64bits CPUs in the affinity mask of a 32 bits task, which I think makes sense. But what about affinity change via cpusets? e.g., if a 32 bit task is migrated to a cpuset with 64 bit CPUs, then the migration will be 'successful' and the task will appear to be in the destination cgroup, but the actual affinity of the task will be something completely different? That's a bit yuck, but I'm not sure what else can be done here :/ Thanks, Quentin From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FSL_HELO_FAKE, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5624AC6369E for ; Thu, 19 Nov 2020 09:49:18 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C82A7246E0 for ; Thu, 19 Nov 2020 09:49:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ddqmsVc5"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="boKOL+16" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C82A7246E0 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=VXEU7y9UEgz9H4ch5IkMyT5kVze3Wgu2Lx88EKbUwC4=; b=ddqmsVc5wLjrJnUS+MI3TFFj2 KSEYcnGvaVPl88IJ6Al2arLPr4waHb0Ri9XGOKaWbuAgc0mnd+dWWiRixVoYZsK2PHiifkyRx3wsi Q+LZ7mncKf8XY9bMzoRoc5P4SGbNO3qcmuJdU3rjuOC+ZZE9inB4EKzQ4QX/gmdXJMHslbZw7dBjr u5/12W7lm9v7t/ahRFPXg8UznT5gZgJ7XkpEpH7fJ8rpOyBn0Hj8FW4EJb82svk5S4bX2Q4FI7p1s e10l2+5OA8FU8JHn6gp6xZrC3MbSI8vpo91J9JumqM4woI93CCxaWG5vfMYGmeEQqXQh24oxH3PSf zg77zas5g==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kfgXh-0003YH-1U; Thu, 19 Nov 2020 09:47:53 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kfgXd-0003X0-Mx for linux-arm-kernel@lists.infradead.org; Thu, 19 Nov 2020 09:47:50 +0000 Received: by mail-wr1-x444.google.com with SMTP id b6so5748715wrt.4 for ; Thu, 19 Nov 2020 01:47:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=g38xN0FDkwhpZzEhM271vqmkWxD69SkDmYogp+3razQ=; b=boKOL+16LzadIMhdXR656SedOKYpIvGLcI2AlaTC8Cq/lTr1baf1u6HUNT0bASYkOa oAu7td6myhRWROuJEHaBafytCXTqNsIGaFKD6r2Mct8z14nDy99MyyDHmv5KE67UW7IG llq1B0K5zfJc6KCxhEQnfYFzwXSeZkQ0S4rtHHbNkXkO6fz8U7dNbxpe1pRGExnF+28q rC2hPzCMf0ru3+/G4fUey+Mrm4v0ZgLHqaQfKxA5DTv+WEtv4CugZoqnv4a8FkHi/Dz/ 2o5xBJeoBZjGCYxP8UyZomtfMeQHNYoqI+RKO57kxdbpaKGNkl/mV2xQypznsLu1wTx2 rnyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=g38xN0FDkwhpZzEhM271vqmkWxD69SkDmYogp+3razQ=; b=gpASrqCBpFeoxQJli7Rq0vOy71/GJ/Abb47FGx/7BtQB0kI1wAVhV3MgXh1rdQa94Q 4rL73VzCoMyd5PnkX2aBRTOtyibv/0qxZ1l5C5YMU5EnWPe3guYQv4UsILaXJ0R1r5CQ WQL33NUirLkDAU9S5ATAoPgWKgMxFok0pFyOJoTP55p1ij5xYnIzjk1MEuVIeuWE2neg QK2WLZvfmOyBUTxnc2i8KLrNkpFZAuP/HmNYuGBxT33ly3c4coxgSZReIu2ccb30VGpK 4C/vR8VljWKYkaVU3Y4N6YEL/VmYvDmLcIrn1jLiHJxanQsZMf07SGlEmAwtHEuey17T +/6A== X-Gm-Message-State: AOAM533eqNI5fKfb4gu1foN6K3z8jS+LBsmecAumpeetPaPvvYApa+w9 /4tB2+x9/Ok1CQ2yt/8Zt3uESA== X-Google-Smtp-Source: ABdhPJzSkfKT2wUMTd6J8oqmowCmaCTnckpBFf352uxLmwWqYQq4slZX+ptNmWR0V342nxkaJPvwNg== X-Received: by 2002:a5d:4612:: with SMTP id t18mr9098818wrq.401.1605779268509; Thu, 19 Nov 2020 01:47:48 -0800 (PST) Received: from google.com ([2a00:79e0:d:210:f693:9fff:fef4:a7ef]) by smtp.gmail.com with ESMTPSA id h20sm8303072wmb.29.2020.11.19.01.47.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 01:47:48 -0800 (PST) Date: Thu, 19 Nov 2020 09:47:44 +0000 From: Quentin Perret To: Will Deacon Subject: Re: [PATCH v3 11/14] sched: Reject CPU affinity changes based on arch_cpu_allowed_mask() Message-ID: <20201119094744.GE2416649@google.com> References: <20201113093720.21106-1-will@kernel.org> <20201113093720.21106-12-will@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20201113093720.21106-12-will@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201119_044749_850939_F1CDDEA7 X-CRM114-Status: GOOD ( 24.55 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, Marc Zyngier , kernel-team@android.com, Vincent Guittot , Juri Lelli , Ingo Molnar , Peter Zijlstra , Catalin Marinas , Johannes Weiner , linux-kernel@vger.kernel.org, Qais Yousef , Li Zefan , Greg Kroah-Hartman , Tejun Heo , Suren Baghdasaryan , Morten Rasmussen , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Friday 13 Nov 2020 at 09:37:16 (+0000), Will Deacon wrote: > Reject explicit requests to change the affinity mask of a task via > set_cpus_allowed_ptr() if the requested mask is not a subset of the > mask returned by arch_cpu_allowed_mask(). This ensures that the > 'cpus_mask' for a given task cannot contain CPUs which are incapable of > executing it, except in cases where the affinity is forced. > > Signed-off-by: Will Deacon > --- > kernel/sched/core.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/kernel/sched/core.c b/kernel/sched/core.c > index 8df38ebfe769..13bdb2ae4d3f 100644 > --- a/kernel/sched/core.c > +++ b/kernel/sched/core.c > @@ -1877,6 +1877,7 @@ static int __set_cpus_allowed_ptr_locked(struct task_struct *p, > struct rq_flags *rf) > { > const struct cpumask *cpu_valid_mask = cpu_active_mask; > + const struct cpumask *cpu_allowed_mask = arch_cpu_allowed_mask(p); > unsigned int dest_cpu; > int ret = 0; > > @@ -1887,6 +1888,9 @@ static int __set_cpus_allowed_ptr_locked(struct task_struct *p, > * Kernel threads are allowed on online && !active CPUs > */ > cpu_valid_mask = cpu_online_mask; > + } else if (!cpumask_subset(new_mask, cpu_allowed_mask)) { > + ret = -EINVAL; > + goto out; So, IIUC, this should make the sched_setaffinity() syscall fail and return -EINVAL to userspace if it tries to put 64bits CPUs in the affinity mask of a 32 bits task, which I think makes sense. But what about affinity change via cpusets? e.g., if a 32 bit task is migrated to a cpuset with 64 bit CPUs, then the migration will be 'successful' and the task will appear to be in the destination cgroup, but the actual affinity of the task will be something completely different? That's a bit yuck, but I'm not sure what else can be done here :/ Thanks, Quentin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel