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 866B0C433F5 for ; Fri, 26 Nov 2021 22:17:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B47736B0075; Fri, 26 Nov 2021 17:16:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AF7346B0078; Fri, 26 Nov 2021 17:16:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 970F06B007B; Fri, 26 Nov 2021 17:16:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0086.hostedemail.com [216.40.44.86]) by kanga.kvack.org (Postfix) with ESMTP id 8533F6B0075 for ; Fri, 26 Nov 2021 17:16:58 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 4EF1C89930 for ; Fri, 26 Nov 2021 22:16:48 +0000 (UTC) X-FDA: 78852492096.08.F6DEDBD Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf06.hostedemail.com (Postfix) with ESMTP id 9D6F6801A89C for ; Fri, 26 Nov 2021 22:16:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=EntB1bbOJyfmGweu3RU+T8l6UeFUccPmGGuVsMlG2Eo=; b=AC8lhUU5E49eFZoE4e2sHAnAX9 kHHIAqB6luQZYLE4LWZ7ew4taByaDQ3nIwp6HUbjkeIXIYYgmmvQyL++HpXPPAuEoWjKaVtpuUv0J hDRUuMHv3vB6OavPVAlSbd8/4HJNbAj7iGK8yieFViHswVFTxtksTJZiwGFqbhpneWAr3PTa5BBq5 cXM7HmcBycjUxcQ73JPFl0lFgYBu+hi3Be2LqMatUPmHoWKFaBNHeb3mn7R7UQBMcP8MuOo3H/d1D paiCR2xp77kYzrGSFDvuDHl6XvX6ujijYsTZOu2obCZpfqqjmUiurJR2T6IOuSr/GsmMrTSNQFSlW JMOb6tZA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqjWN-00CN1H-DW; Fri, 26 Nov 2021 22:16:44 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 4E2D83000DD; Fri, 26 Nov 2021 23:16:43 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 338A52DC5775F; Fri, 26 Nov 2021 23:16:43 +0100 (CET) Date: Fri, 26 Nov 2021 23:16:43 +0100 From: Peter Zijlstra To: Peter Oskolkov Cc: Ingo Molnar , Thomas Gleixner , Andrew Morton , Dave Hansen , Andy Lutomirski , Linux Memory Management List , Linux Kernel Mailing List , linux-api@vger.kernel.org, Paul Turner , Ben Segall , Peter Oskolkov , Andrei Vagin , Jann Horn , Thierry Delisle Subject: Re: [PATCH v0.9.1 3/6] sched/umcg: implement UMCG syscalls Message-ID: References: <20211122211327.5931-1-posk@google.com> <20211122211327.5931-4-posk@google.com> <20211124200822.GF721624@worktop.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Stat-Signature: 47ufeqe5gim3a96h33zmd4wdaga1qsxg Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=AC8lhUU5; dmarc=none; spf=none (imf06.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 9D6F6801A89C X-HE-Tag: 1637965006-289324 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 Fri, Nov 26, 2021 at 06:09:10PM +0100, Peter Zijlstra wrote: > @@ -155,8 +159,7 @@ static unsigned long exit_to_user_mode_l > * Before returning to user space ensure that all pending work > * items have been completed. > */ > - while (ti_work & EXIT_TO_USER_MODE_WORK) { > - > + do { > local_irq_enable_exit_to_user(ti_work); > > if (ti_work & _TIF_NEED_RESCHED) > @@ -168,6 +171,10 @@ static unsigned long exit_to_user_mode_l > if (ti_work & _TIF_PATCH_PENDING) > klp_update_patch_state(current); > > + /* must be before handle_signal_work(); terminates on sigpending */ > + if (ti_work & _TIF_UMCG) > + umcg_notify_resume(regs); > + > if (ti_work & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL)) > handle_signal_work(regs, ti_work); > > @@ -188,7 +195,7 @@ static unsigned long exit_to_user_mode_l > tick_nohz_user_enter_prepare(); > > ti_work = READ_ONCE(current_thread_info()->flags); > - } > + } while (ti_work & EXIT_TO_USER_MODE_WORK); > > /* Return the latest work state for arch_exit_to_user_mode() */ > return ti_work; > @@ -203,7 +210,7 @@ static void exit_to_user_mode_prepare(st > /* Flush pending rcuog wakeup before the last need_resched() check */ > tick_nohz_user_enter_prepare(); > > - if (unlikely(ti_work & EXIT_TO_USER_MODE_WORK)) > + if (unlikely(ti_work & (EXIT_TO_USER_MODE_WORK | _TIF_UMCG))) > ti_work = exit_to_user_mode_loop(regs, ti_work); > > arch_exit_to_user_mode_prepare(regs, ti_work); Thomas, since you're looking at this. I'm not quite sure I got this right. The intent is that when _TIF_UMCG is set (and it is never cleared until the task unregisters) it is called at least once. The thinking is that if umcg_wait() gets interrupted, we'll drop out, handle the signal and then resume the wait, which can obviously happen any number of times. It's just that I'm never quite sure where signal crud happens; I'm assuming handle_signal_work() simply mucks about with regs (sets sp and ip etc.. to the signal stack) and drops out of kernel mode, and on re-entry we do this whole merry cycle once again. But I never actually dug that deep.