Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3695795pxb; Fri, 5 Nov 2021 21:43:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtAX1qtKoOONVjmC+UlqzOwDasx6YkkgceDPx5mrHoiE5U5xZwTwXyNNY0tFc8Sc1R8ZJH X-Received: by 2002:a5d:9e15:: with SMTP id h21mr2559054ioh.175.1636173811113; Fri, 05 Nov 2021 21:43:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1636173811; cv=none; d=google.com; s=arc-20160816; b=SEMq0lVr0FWYqigmGsjznJo8K6g8JZJTVfNtIvkFwIruMpEgO2QqB3TASkwD5lZgvV K2Y/R2c3KzLGG7uBH4DEZIoh4koyE2wENvcQaG8/A3L7pl4e7UYxn8QrSZNOwjo8fomy 9efQVDr87iAAHl53NbevI6Y36NhnqIlbKC64P8WSgSaAFNNtafBwvzpNId2LT0/5VB6x Xb7/iFdnRkX/4lDzF3qfllBQkreS7RpuVqBQtmvzhLMY2X+p84Yoiu/qA9B+X7SawX74 9R0ic6dPCGlKqoQZQ1NroD8/EohbJJgsVdcTTWSo0+19nqLSY02jcP6UscxhinblHgnp 87LQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :mime-version:user-agent:date:message-id:from:in-reply-to:references :cc:to:subject:ironport-data:dkim-signature; bh=wWdoVzl9PsM1vlTzRS53F8xIvsftDLciPipuIlcpB6s=; b=ybav2NIMrnIc3+4f9v+jOWNiL7Yj3dT75CzMIB+yyu4zJS7htT04AX3wJPoYcmeOW9 l2wEPatPvlSmFmrvG8SLYNVLdFvSfSJQmjOHU85ggjyoIU706xYW9YJxUeVRM9cHj1IB B8ytcgbPUqbOWZqfaDEfZrHhhWwnFbviSD6/CSU/t3EYjKiY8rbljh275h5tekxnIWWv WaD0xElDTfxGdxL7A+xYcKIWn+bRFXsWL84RLSZ7hEp+I84am7AOdGiMut2S5ZA4nS4s IZ1i8gyVYEVxxv8IdTb6uY28K8XVuQjfUc+LNr2N0tyXtnzOfrWjLs2Q2sNoVJM3VjEL 6urg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@uwaterloo.ca header.s=default header.b=+djJ3CYv; 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=fail (p=NONE sp=NONE dis=NONE) header.from=uwaterloo.ca Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ay5si17583780jab.64.2021.11.05.21.43.18; Fri, 05 Nov 2021 21:43:31 -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=fail header.i=@uwaterloo.ca header.s=default header.b=+djJ3CYv; 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=fail (p=NONE sp=NONE dis=NONE) header.from=uwaterloo.ca Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233038AbhKEXvH (ORCPT + 99 others); Fri, 5 Nov 2021 19:51:07 -0400 Received: from esa.hc503-62.ca.iphmx.com ([216.71.131.47]:15715 "EHLO esa.hc503-62.ca.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233175AbhKEXvG (ORCPT ); Fri, 5 Nov 2021 19:51:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=uwaterloo.ca; i=@uwaterloo.ca; q=dns/txt; s=default; t=1636156106; x=1667692106; h=subject:to:cc:references:in-reply-to:from:message-id: date:mime-version:content-transfer-encoding; bh=0czp8HPimoHrpAqsPvqIllMPMs8etJtDQEcHMcp5MUU=; b=+djJ3CYv3sf/LJ+uLrsxAT5W6tiHd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DwWDEJoNMkDUSXkb E/apUVa45o7FGOncaJtcaqwDcowxKTtHNijUerbBvJWZYNyXBeA5yIoZEn44oz2uEMrl6cyM ovdbNmlEXsADaNgijG/LwsA7YIWKukF7Tu7bfjGI96PiNJyuFb9pW85DWaz Received: from connect.uwaterloo.ca (HELO connhm04.connect.uwaterloo.ca) ([129.97.208.43]) by ob1.hc503-62.ca.iphmx.com with ESMTP/TLS/AES256-GCM-SHA384; 05 Nov 2021 19:48:22 -0400 Received: from [10.42.0.123] (10.32.137.240) by connhm04.connect.uwaterloo.ca (172.16.137.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.14; Fri, 5 Nov 2021 19:48:21 -0400 Subject: Re: [PATCH v0.8 3/6] sched/umcg: implement UMCG syscalls To: Peter Oskolkov , Peter Zijlstra , Ingo Molnar , Thomas Gleixner , Andrew Morton , Dave Hansen , Andy Lutomirski , , , CC: Paul Turner , Ben Segall , Peter Oskolkov , Andrei Vagin , Jann Horn References: <20211104195804.83240-1-posk@google.com> <20211104195804.83240-4-posk@google.com> In-Reply-To: <20211104195804.83240-4-posk@google.com> From: Thierry Delisle Message-ID: Date: Fri, 5 Nov 2021 19:48:21 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Originating-IP: [10.32.137.240] X-ClientProxiedBy: connhm02.connect.uwaterloo.ca (172.16.137.66) To connhm04.connect.uwaterloo.ca (172.16.137.68) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-11-04 3:58 p.m., Peter Oskolkov wrote: > +/* > + * Try to wake up. May be called with preempt_disable set. May be called > + * cross-process. > + * > + * Note: umcg_ttwu succeeds even if ttwu fails: see wait/wake state > + *       ordering logic. > + */ > +static int umcg_ttwu(u32 next_tid, int wake_flags) > +{ > +    struct task_struct *next; > + > +    rcu_read_lock(); > +    next = find_task_by_vpid(next_tid); > +    if (!next || !umcg_wakeup_allowed(next)) { > +        rcu_read_unlock(); > +        return -ESRCH; > +    } > + > +    /* The result of ttwu below is ignored. */ > +    try_to_wake_up(next, TASK_NORMAL, wake_flags); > +    rcu_read_unlock(); > + > +    return 0; > +} Doesn't try_to_wake_up return different values based on whether or not a task was woken up? I think it could be useful to propagate that result instead of always returning zero. Even if it only helps for debugging. > +static bool enqueue_idle_worker(struct umcg_task __user *ut_worker) > +{ > +    u64 __user *node = &ut_worker->idle_workers_ptr; > +    u64 __user *head_ptr; > +    u64 first = (u64)node; > +    u64 head; > + > +    if (get_user(head, node) || !head) > +        return false; > + > +    head_ptr = (u64 __user *)head; > + > +    /* Mark the worker as pending. */ > +    if (put_user(UMCG_IDLE_NODE_PENDING, node)) > +        return false; > + > +    /* Make the head point to the worker. */ > +    if (xchg_user_64(head_ptr, &first)) > +        return false; > + > +    /* Make the worker point to the previous head. */ > +    if (put_user(first, node)) > +        return false; > + > +    return true; > +} If the last two operation return false, whichever task tries to consume the list could deadlock, depending on whether or not the ensuing force_sig(SIGKILL); reaches the consuming task. Does the force_sig kill the task or the entire process. Is it possible to consume this list from a different process that shares the memory? I'm wondering if the last two "return false" should attempt to retract the UMCG_IDLE_NODE_PENDING.