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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83DDAC433EF for ; Thu, 27 Jan 2022 18:33:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DE7CC6B0072; Thu, 27 Jan 2022 13:33:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D97FF6B0074; Thu, 27 Jan 2022 13:33:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C5FD66B0075; Thu, 27 Jan 2022 13:33:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0173.hostedemail.com [216.40.44.173]) by kanga.kvack.org (Postfix) with ESMTP id B808C6B0072 for ; Thu, 27 Jan 2022 13:33:22 -0500 (EST) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 802E2181B5EA6 for ; Thu, 27 Jan 2022 18:33:22 +0000 (UTC) X-FDA: 79076914644.27.69072C1 Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by imf19.hostedemail.com (Postfix) with ESMTP id 00A3F1A0002 for ; Thu, 27 Jan 2022 18:33:21 +0000 (UTC) Date: Fri, 28 Jan 2022 02:33:16 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1643308400; 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: in-reply-to:in-reply-to:references:references; bh=SVqeRfTnsDsLypLNnH4fgggsQaxIu1PGm+k1vPPQ5XU=; b=Ry8pLBkgu9CQJBV8Qrr/MymnU3+FUy8SP4qwSmI2wsw2carhgPUZ/kfCFqvvsFRogIsdMr niLcZ0tYZ8cdb86fK4ID0Jwvrj/3QCvNMCaWXIZgxyIh3XxDVrqGj2tS4QnGKYnpVlCTJT gHz56owtxtf9BbSd4QlziaFZkhb4/4Q= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Tao Zhou To: Peter Zijlstra Cc: mingo@redhat.com, tglx@linutronix.de, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-api@vger.kernel.org, x86@kernel.org, pjt@google.com, posk@google.com, avagin@google.com, jannh@google.com, tdelisle@uwaterloo.ca, mark.rutland@arm.com, posk@posk.io, Tao Zhou Subject: Re: [RFC][PATCH v2 5/5] sched: User Mode Concurency Groups Message-ID: References: <20220120155517.066795336@infradead.org> <20220120160822.914418096@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 00A3F1A0002 X-Stat-Signature: ef4p5qdobxjixdbyf5mmiyjb71t66eyc Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Ry8pLBkg; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf19.hostedemail.com: domain of tao.zhou@linux.dev designates 188.165.223.204 as permitted sender) smtp.mailfrom=tao.zhou@linux.dev X-Rspam-User: nil X-HE-Tag: 1643308401-418910 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 Thu, Jan 27, 2022 at 01:19:43PM +0100, Peter Zijlstra wrote: > On Mon, Jan 24, 2022 at 10:46:17PM +0800, Tao Zhou wrote: > > Hi Peter, > > > > On Thu, Jan 20, 2022 at 04:55:22PM +0100, Peter Zijlstra wrote: > > > > [...] > > > > > +/* pre-schedule() */ > > > +void umcg_wq_worker_sleeping(struct task_struct *tsk) > > > +{ > > > + struct umcg_task __user *self = READ_ONCE(tsk->umcg_task); > > > + int ret; > > > + > > > + if (!tsk->umcg_server) { > > > + /* > > > + * Already blocked before, the pages are unpinned. > > > + */ > > > + return; > > > + } > > > + > > > + /* Must not fault, mmap_sem might be held. */ > > > + pagefault_disable(); > > > + > > > + ret = umcg_update_state(tsk, self, UMCG_TASK_RUNNING, UMCG_TASK_BLOCKED); > > > + if (ret == -EAGAIN) { > > > + /* > > > + * Consider: > > > + * > > > + * self->state = UMCG_TASK_RUNNABLE | UMCG_TF_COND_WAIT; > > > + * ... > > > + * sys_umcg_wait(); > > > + * > > > + * and the '...' code doing a blocking syscall/fault. This > > > + * ensures that returns with UMCG_TASK_RUNNING, which will make > > > > /UMCG_TASK_RUNNING/UMCG_TASK_RUNNABLE/ > > So the issue is that: > > self->state = UMCG_TASK_RUNNABLE | UMCG_TF_COND_WAIT; > > <#PF> > umcg_sys_enter() > umcg_pin_user_page() > schedule() > sched_submit_work() > umcg_wq_worker_sleeping() > umcg_update_state(tsk, self, UMCG_TASK_RUNNING, UMCG_TASK_BLOCKED) // -EAGAIN > UMCG_DIE() > > Which is clearly not desirable. > > So this additinoal thing ensures that: > > umcg_update_state(tsk, self, UMCG_TASK_RUNNABLE, UMCG_TASK_BLOCKED) // 0 > > umcg_sys_exit() > umcg_update_state(tsk, self, UMCG_TASK_BLOCKED, UMCG_TASK_RUNNABLE); > umcg_enqueue_and_wake() > > umcg_notify_resume() > umcg_wait() > > // must be UMCG_TASK_RUNNING here > > > So when the pagefault finally does return, it will have: > UMCG_TASK_RUNNING. > > Which will then make sys_umcg_wait() return -EAGAIN and around we go. Thank you, Peter. > > > + * sys_umcg_wait() return with -EAGAIN. > > > + */ > > > + ret = umcg_update_state(tsk, self, UMCG_TASK_RUNNABLE, UMCG_TASK_BLOCKED); > > > + } > > > + if (ret) > > > + UMCG_DIE_PF("state"); > > > + > > > + if (umcg_wake_server(tsk)) > > > + UMCG_DIE_PF("wake"); > > > + > > > + pagefault_enable(); > > > + > > > + /* > > > + * We're going to sleep, make sure to unpin the pages, this ensures > > > + * the pins are temporary. Also see umcg_sys_exit(). > > > + */ > > > + umcg_unpin_pages(); > > > +}