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 DA501C433F5 for ; Fri, 7 Oct 2022 18:59:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229506AbiJGS7z (ORCPT ); Fri, 7 Oct 2022 14:59:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229508AbiJGS7w (ORCPT ); Fri, 7 Oct 2022 14:59:52 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 918771FCC5 for ; Fri, 7 Oct 2022 11:59:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665169188; 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=sQGHWYEn+LWtlygubAjFbTrPolfuQ9vkB0zrJq+x8Yk=; b=NiXHjNYaqhAcOvntctWI/Tv601NWka0YtpjI/u6BXp1qpsoIl4cl32yht4C0XjiONzUfAH ph7BoX4y1lJuNdXOgNwdur4tkw5RlwC8NtnmkkvGCwOYKmsT2Hvik4tNRc+pSTuZIg8Mx1 /BJ9KKMal4DvArxauRCh6tIdspBKIdU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-14-G0jtj07VPp-GbuKeqEGRlw-1; Fri, 07 Oct 2022 14:59:45 -0400 X-MC-Unique: G0jtj07VPp-GbuKeqEGRlw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E51AD882821; Fri, 7 Oct 2022 18:59:44 +0000 (UTC) Received: from [10.22.18.97] (unknown [10.22.18.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9EDA740EFB3A; Fri, 7 Oct 2022 18:59:42 +0000 (UTC) Message-ID: <463d3d8d-5d6c-6c83-561b-199ab1bd8887@redhat.com> Date: Fri, 7 Oct 2022 14:59:42 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Subject: Re: [PATCH v10 4/5] sched: Handle set_cpus_allowed_ptr(), sched_setaffinity() & other races Content-Language: en-US To: Peter Zijlstra Cc: Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Tejun Heo , Zefan Li , Johannes Weiner , Will Deacon , linux-kernel@vger.kernel.org, Linus Torvalds , Lai Jiangshan References: <20220922180041.1768141-1-longman@redhat.com> <20220922180041.1768141-5-longman@redhat.com> From: Waiman Long In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/7/22 08:47, Peter Zijlstra wrote: > On Thu, Sep 22, 2022 at 02:00:40PM -0400, Waiman Long wrote: >> Racing is possible between set_cpus_allowed_ptr() and sched_setaffinity() >> or between multiple sched_setaffinity() calls from different >> CPUs. To resolve these race conditions, we need to update both >> user_cpus_ptr and cpus_mask in a single lock critical section instead >> of separated ones. This requires moving the user_cpus_ptr update >> to set_cpus_allowed_common() by putting the user_mask into a new >> affinity_context structure and using it to pass information around >> various functions. >> >> This patch also changes the handling of the race between the >> sched_setaffinity() call and the changing of cpumask of the current >> cpuset. In case the new mask conflicts with newly updated cpuset, >> the cpus_mask will be reset to the cpuset cpumask and an error value >> of -EINVAL will be returned. If a previous user_cpus_ptr value exists, >> it will be swapped back in and the new_mask will be further restricted >> to what is allowed in the cpumask pointed to by the old user_cpus_ptr. >> >> The potential race between sched_setaffinity() and a fork/clone() >> syscall calling dup_user_cpus_ptr() is also being handled. > This is still arse-backwards... You're still fixing races you've > introduced earlier in the series. > > Since I don't think telling you again is going to help; I've done it for > you :/ How's this then? > > https://git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git/log/?h=sched/affinity > Thank you very much for updating the patch series. Beside the minor nit that I talked about in the previous mail, the result looks good to me. Do you mind if I send another patch on top of your branch to make the adjustment or you want to do it yourself? Cheers, Longman