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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2CFA4C25B0E for ; Tue, 16 Aug 2022 22:11:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237886AbiHPWLP (ORCPT ); Tue, 16 Aug 2022 18:11:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237869AbiHPWLL (ORCPT ); Tue, 16 Aug 2022 18:11:11 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97D128F975 for ; Tue, 16 Aug 2022 15:11:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660687869; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K219zFXEgyRo40dCsRP0DxF0BwKck2dNw2HkaSxa61Y=; b=V6lRhCG0d30EnyWkmwoVnyYLQztQ69pHDJBLzkP/1I/9y9SZjrLYtqMXPqefvmijN5YcT7 gIs4hIHz1nlLWBq7UjUnaP930n6KstCPKDAzm0KC+xarxdc2/OuUdIwPHzofMceaOesxH/ 7y3q5xTDIStkDR/O23bEskkmsMpf5lc= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-645-QGgImqF0P82MT71U89AKng-1; Tue, 16 Aug 2022 18:11:05 -0400 X-MC-Unique: QGgImqF0P82MT71U89AKng-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E714329ABA39; Tue, 16 Aug 2022 22:11:04 +0000 (UTC) Received: from [10.22.16.150] (unknown [10.22.16.150]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9A5BD2026D4C; Tue, 16 Aug 2022 22:11:03 +0000 (UTC) Message-ID: Date: Tue, 16 Aug 2022 18:11:03 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v5 3/3] cgroup/cpuset: Keep user set cpus affinity Content-Language: en-US To: Tejun Heo Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Zefan Li , Johannes Weiner , Will Deacon , cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Linus Torvalds References: <20220816192734.67115-1-longman@redhat.com> <20220816192734.67115-4-longman@redhat.com> From: Waiman Long In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 8/16/22 16:15, Tejun Heo wrote: > On Tue, Aug 16, 2022 at 03:27:34PM -0400, Waiman Long wrote: >> +static int cpuset_set_cpus_allowed_ptr(struct task_struct *p, >> + const struct cpumask *mask) >> +{ >> + cpumask_var_t new_mask; >> + int ret; >> + >> + if (!READ_ONCE(p->user_cpus_ptr)) { >> + ret = set_cpus_allowed_ptr(p, mask); >> + /* >> + * If user_cpus_ptr becomes set now, we are racing with >> + * a concurrent sched_setaffinity(). So use the newly >> + * set user_cpus_ptr and retry again. >> + * >> + * TODO: We cannot detect change in the cpumask pointed to >> + * by user_cpus_ptr. We will have to add a sequence number >> + * if such a race needs to be addressed. >> + */ > This is too ugly and obviously broken. Let's please do it properly. Actually, there is similar construct in __sched_setaffinity(): again:         retval = __set_cpus_allowed_ptr(p, new_mask, SCA_CHECK);         if (retval)                 goto out_free_new_mask;         cpuset_cpus_allowed(p, cpus_allowed);         if (!cpumask_subset(new_mask, cpus_allowed)) {                 /*                  * We must have raced with a concurrent cpuset update.                  * Just reset the cpumask to the cpuset's cpus_allowed.                  */                 cpumask_copy(new_mask, cpus_allowed);                 goto again;         } It is hard to synchronize different subsystems atomically without running into locking issue. Let me think about what can be done in this case. Is using a sequence number to check for race with retry good enough? Cheers, Longman