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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 069BEC433F5 for ; Fri, 5 Nov 2021 23:48:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 81E706120D for ; Fri, 5 Nov 2021 23:48:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 81E706120D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=uwaterloo.ca Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id CB022940020; Fri, 5 Nov 2021 19:48:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C608D94000D; Fri, 5 Nov 2021 19:48:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ADAF2940020; Fri, 5 Nov 2021 19:48:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0170.hostedemail.com [216.40.44.170]) by kanga.kvack.org (Postfix) with ESMTP id 9DF8894000D for ; Fri, 5 Nov 2021 19:48:26 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 5EA7E76E1A for ; Fri, 5 Nov 2021 23:48:26 +0000 (UTC) X-FDA: 78776518212.15.E78015E Received: from esa.hc503-62.ca.iphmx.com (esa.hc503-62.ca.iphmx.com [216.71.131.47]) by imf06.hostedemail.com (Postfix) with ESMTP id B1BEF801A8BF for ; Fri, 5 Nov 2021 23:48:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=uwaterloo.ca; i=@uwaterloo.ca; q=dns/txt; s=default; t=1636156105; x=1667692105; h=subject:to:cc:references:in-reply-to:from:message-id: date:mime-version:content-transfer-encoding; bh=0czp8HPimoHrpAqsPvqIllMPMs8etJtDQEcHMcp5MUU=; b=lLWlNtlaxadfrWpSUe4S4RgNZMALx+n23JxI/1Cz3N7Q/iBZmnHXQ86q 3bOjoNBSPbVK8hGIH2tv2uKayyYzEiwxNOafHJbe6d2Z+IKYYNgz2wVYt 8cucGX5kOIK4Q4JvPe16aMOdGSYRcEOjFysLTD4rjmD0Ccs5pO084xc80 g=; IronPort-Data: A9a23:bpprgq8fh9aiqbfFR6w0DrUDO3+TJUtcMsCJ2f8bNWPcYEJGY0x3z mofDDzQaPyPZ2GmKdpybovlpElTsMfXxocxSgo5/HhEQiMRo6IpJzg4wmQcnc+2BpeeJK6yx 5xGMrEsCuhqFieEzvuKGue99iYUOZllwtMQMcacUsxLbVYMpBwJ1FQzxIbVvqYy2YLgWlrV5 IupyyHiEAbNNwBcYzN8B52r9UsHUMTa4Fv0aXRnOJinFHeH/5UkJMp3yZOZdhMUcaEIdgKOf Nsv+Znilo/vE7XBPfv++lrzWhVirrc/pmFigFIOM0SpqkAqSiDfTs/XnRfTAKtao2zhojx/9 DlCnYyNFxoyALTUouFDUxZfHw09ErcB24aSdBBTseTLp6HHW3DrxfNuCRlqe4Yf/OB6Cn0I6 OMRND0XaheEwem/qF65YrA214Jyc4+xZNNZ5ioIITLxVJ7KRbjfT6jO5MRc0R8tmclSEOzaY M1fYjMHgBHoOUcQYgxMWcNWcOGAxST1Ug9foVCsnbM6/mbhyjZB06jUGY+AEjCNbYAP9qqCn UrE9mL/AjkVM9uQzTfD+XWp7sfGgyr0WYQ6G7q/+fpnxlaUwwQ7EBoNVnO0pv62jkP4UNVaQ 2Qe4SchpKw23EOsSdb5Uluzp3vslgYeR/JfFOo17AzLwa3Riy6dB24ZXntIcN0OqsA7X3op2 0WPktevAiZg2JWRSHSA5vKXoCm0NCw9M2APf2kHQBED7t2lp5s85jrLT9B+AOuwi/X2Bzj7w HaNtidWr7EOkckj1Kih+13DxTW2qfDhQgcr60PXV2S+4wVRYI+jepzu6F7H4PIGJ4GcJnGIv 2ABs8yf6v0eSJ+KiSqBSfkMG7fv4OyKWBXAjlp/N50g8Smx4XmlfJAW7DwWDEJoNMkDUSXkb 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-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) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=uwaterloo.ca header.s=default header.b=lLWlNtla; spf=pass (imf06.hostedemail.com: domain of tdelisle@uwaterloo.ca designates 216.71.131.47 as permitted sender) smtp.mailfrom=tdelisle@uwaterloo.ca; dmarc=pass (policy=none) header.from=uwaterloo.ca X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: B1BEF801A8BF X-Stat-Signature: n9o156b9k1ojme3ybha1m9do1ws8s5wf X-HE-Tag: 1636156105-302391 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 2021-11-04 3:58 p.m., Peter Oskolkov wrote: > +/* > + * Try to wake up. May be called with preempt_disable set. May be cal= led > + * cross-process. > + * > + * Note: umcg_ttwu succeeds even if ttwu fails: see wait/wake state > + *=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ordering logic. > + */ > +static int umcg_ttwu(u32 next_tid, int wake_flags) > +{ > +=C2=A0=C2=A0 =C2=A0struct task_struct *next; > + > +=C2=A0=C2=A0 =C2=A0rcu_read_lock(); > +=C2=A0=C2=A0 =C2=A0next =3D find_task_by_vpid(next_tid); > +=C2=A0=C2=A0 =C2=A0if (!next || !umcg_wakeup_allowed(next)) { > +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0rcu_read_unlock(); > +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return -ESRCH; > +=C2=A0=C2=A0 =C2=A0} > + > +=C2=A0=C2=A0 =C2=A0/* The result of ttwu below is ignored. */ > +=C2=A0=C2=A0 =C2=A0try_to_wake_up(next, TASK_NORMAL, wake_flags); > +=C2=A0=C2=A0 =C2=A0rcu_read_unlock(); > + > +=C2=A0=C2=A0 =C2=A0return 0; > +} Doesn't try_to_wake_up return different values based on whether or not a=20 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) > +{ > +=C2=A0=C2=A0 =C2=A0u64 __user *node =3D &ut_worker->idle_workers_ptr; > +=C2=A0=C2=A0 =C2=A0u64 __user *head_ptr; > +=C2=A0=C2=A0 =C2=A0u64 first =3D (u64)node; > +=C2=A0=C2=A0 =C2=A0u64 head; > + > +=C2=A0=C2=A0 =C2=A0if (get_user(head, node) || !head) > +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return false; > + > +=C2=A0=C2=A0 =C2=A0head_ptr =3D (u64 __user *)head; > + > +=C2=A0=C2=A0 =C2=A0/* Mark the worker as pending. */ > +=C2=A0=C2=A0 =C2=A0if (put_user(UMCG_IDLE_NODE_PENDING, node)) > +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return false; > + > +=C2=A0=C2=A0 =C2=A0/* Make the head point to the worker. */ > +=C2=A0=C2=A0 =C2=A0if (xchg_user_64(head_ptr, &first)) > +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return false; > + > +=C2=A0=C2=A0 =C2=A0/* Make the worker point to the previous head. */ > +=C2=A0=C2=A0 =C2=A0if (put_user(first, node)) > +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return false; > + > +=C2=A0=C2=A0 =C2=A0return true; > +} If the last two operation return false, whichever task tries to consume t= he 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.