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 ED44DC433F5 for ; Fri, 21 Jan 2022 11:48:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 595C36B0085; Fri, 21 Jan 2022 06:48:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 545176B0087; Fri, 21 Jan 2022 06:48:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 45BC06B0089; Fri, 21 Jan 2022 06:48:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0213.hostedemail.com [216.40.44.213]) by kanga.kvack.org (Postfix) with ESMTP id 375796B0085 for ; Fri, 21 Jan 2022 06:48:19 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id E4CB98249980 for ; Fri, 21 Jan 2022 11:48:18 +0000 (UTC) X-FDA: 79054121076.10.5434DC6 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf26.hostedemail.com (Postfix) with ESMTP id 5FB2E140009 for ; Fri, 21 Jan 2022 11:48:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=lFHfkJxcnXYD0/r/G4ykqtBeToVnk/8ZWOb3hXPkSGs=; b=In+XDGoh4xfF62ZOJqOxbFOxvI AyqXSblou41zoHqurVRhHtaM4vPwYhN/jyrxm5ahd2FZ3boobCmk3Slg+6vRxOrajOAs8+V0Ot7Pp C0e4UNjDW9IsxVh4qi6HfYTsg5t+Q6WLQgTvWuAVmHZ+qa7W5VaewfKCftPIazCHqisI44gOBfB3q Yy3w8P/6VuIA+LV+dUwIBBhr0416w4RF5ymf1QZSMmUDlvENSDlBXomFtPTWPxmyh3vwTLS4V7X++ V3jsGYrC8GLOlCHWTl9NfmHFDZNbvUt79RO/BhPhykQZS6a4q9749ad+ZyB/8QVcvHM0YnfYCmUHi GMpFI3bg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=worktop.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1nAsOf-002ZUP-3V; Fri, 21 Jan 2022 11:48:01 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id CE8679853F1; Fri, 21 Jan 2022 12:47:58 +0100 (CET) Date: Fri, 21 Jan 2022 12:47:58 +0100 From: Peter Zijlstra To: 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 Cc: 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 Subject: Re: [RFC][PATCH v2 5/5] sched: User Mode Concurency Groups Message-ID: <20220121114758.GF20638@worktop.programming.kicks-ass.net> 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: <20220120160822.914418096@infradead.org> X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 5FB2E140009 X-Stat-Signature: 69fbz8fw1succqjt5ty75jzwsi57xm53 Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=In+XDGoh; dmarc=none; spf=none (imf26.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org X-HE-Tag: 1642765698-675665 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 20, 2022 at 04:55:22PM +0100, Peter Zijlstra wrote: > +SYSCALL_DEFINE2(umcg_wait, u32, flags, u64, timo) > +{ > + struct task_struct *tsk = current; > + struct umcg_task __user *self = READ_ONCE(tsk->umcg_task); > + bool worker = tsk->flags & PF_UMCG_WORKER; > + int ret; > + > + if (!self || flags) > + return -EINVAL; > + > + if (worker) { > + tsk->flags &= ~PF_UMCG_WORKER; > + if (timo) > + return -ERANGE; > + } > + > + /* see umcg_sys_{enter,exit}() syscall exceptions */ > + ret = umcg_pin_pages(); > + if (ret) > + goto unblock; > + > + /* > + * Clear UMCG_TF_COND_WAIT *and* check state == RUNNABLE. > + */ > + ret = umcg_update_state(tsk, self, UMCG_TASK_RUNNABLE, UMCG_TASK_RUNNABLE); > + if (ret) > + goto unpin; > + > + ret = umcg_wake_next(tsk, self); > + if (ret) > + goto unpin; > + > + if (worker) { > + /* > + * If this fails it is possible ::next_tid is already running > + * while this task is not going to block. This violates our > + * constraints. > + * > + * That said, pretty much the only way to make this fail is by > + * force munmap()'ing things. In which case one is most welcome > + * to the pieces. > + */ > + ret = umcg_enqueue_and_wake(tsk); > + if (ret) > + goto unpin; > + } > + > + umcg_unpin_pages(); > + > + ret = umcg_wait(timo); > + switch (ret) { > + case 0: /* all done */ > + case -EINTR: /* umcg_notify_resume() will continue the wait */ So I was playing with the whole worker timeout thing last night and realized this is broken. If we get a signal while we have a timeout, the timeout gets lost. I think the easiest solution is to have umcg_notify_resume() also resume the timeout, but the first pass of that was yuck, so I need to try again. Related, by moving the whole enqueue-and-wake thing into the timeout, we get more 'fun' failure cases :-( Oh well.. > + ret = 0; > + break; > + > + default: > + goto unblock; > + } > +out: > + if (worker) > + tsk->flags |= PF_UMCG_WORKER; > + return ret; > + > +unpin: > + umcg_unpin_pages(); > +unblock: > + umcg_update_state(tsk, self, UMCG_TASK_RUNNABLE, UMCG_TASK_RUNNING); > + goto out; > +}