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 1058CC433EF for ; Fri, 26 Nov 2021 22:07:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 843C56B0075; Fri, 26 Nov 2021 17:07:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7CC8D6B0078; Fri, 26 Nov 2021 17:07:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 66C716B007B; Fri, 26 Nov 2021 17:07:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0254.hostedemail.com [216.40.44.254]) by kanga.kvack.org (Postfix) with ESMTP id 530C56B0075 for ; Fri, 26 Nov 2021 17:07:46 -0500 (EST) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 096627F8F6 for ; Fri, 26 Nov 2021 22:07:36 +0000 (UTC) X-FDA: 78852468828.11.A7B7245 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf11.hostedemail.com (Postfix) with ESMTP id 9F538F0000AA for ; Fri, 26 Nov 2021 22:07:35 +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=wx8LefqrmaL7hNN7/gVpJleg+PonaO/cczr6R2BoD00=; b=OZq1Qoyl8UMeOifsrrdF/RyTDD pzYzJpPls4qfWAvlDSvhaqpS+B9r7Th236tq1LmAv78J3/lhxwvNqb7r7eNRyL5c77W08oKrWsWDY RpNPr1uTizkMcpvfkmd6rMivZipaj2Tdvmrf1wj4KoPxh+qan1cpQM3poyntYuvwMPt/pvZa2L9Wm Pibf1cVfUpDHEm2ZoDzcbhrbInTW+h/X5BlYzbbBVqMLZXYGEy5W0GyALx/PAWeTtYwjJqpgsfsgH QXu0968ZDUA5fAnRKaoLUVIDl+9KXrLOc7r6dCPbr6t1UFeFkyF4qIUVp4f3Q3odm0qhCJ7FvpYCu 4h239dsQ==; 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 1mqjNR-00CLFd-80; Fri, 26 Nov 2021 22:07:32 +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 27F5E300093; Fri, 26 Nov 2021 23:07:29 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 0743C2DC70762; Fri, 26 Nov 2021 23:07:29 +0100 (CET) Date: Fri, 26 Nov 2021 23:07:29 +0100 From: Peter Zijlstra To: Thomas Gleixner Cc: Peter Oskolkov , Ingo Molnar , 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> <87a6hqhbgh.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Stat-Signature: frzjoe8poa4m8jfgeyxy3er7xu5qogdw X-Rspamd-Queue-Id: 9F538F0000AA X-Rspamd-Server: rspam07 Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=OZq1Qoyl; spf=none (imf11.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org; dmarc=none X-HE-Tag: 1637964455-117377 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 10:59:44PM +0100, Peter Zijlstra wrote: > That seems to loose the freezable crud.. then again, since we're > interruptible, that shouldn't matter. Lemme go do that. --- --- a/kernel/sched/umcg.c +++ b/kernel/sched/umcg.c @@ -52,7 +52,7 @@ static int umcg_pin_pages(void) server = umcg_get_task(server_tid); if (!server) - return -EINVAL; + return -ESRCH; if (pin_user_pages_fast((unsigned long)self, 1, 0, &tsk->umcg_worker_page) != 1) @@ -358,18 +358,10 @@ int umcg_wait(u64 timo) { struct task_struct *tsk = current; struct umcg_task __user *self = tsk->umcg_task; - struct hrtimer_sleeper timeout; struct page *page = NULL; u32 state; int ret; - if (timo) { - hrtimer_init_sleeper_on_stack(&timeout, tsk->umcg_clock, - HRTIMER_MODE_ABS); - hrtimer_set_expires_range_ns(&timeout.timer, (s64)timo, - tsk->timer_slack_ns); - } - for (;;) { set_current_state(TASK_INTERRUPTIBLE); @@ -415,22 +407,16 @@ int umcg_wait(u64 timo) break; } - if (timo) - hrtimer_sleeper_start_expires(&timeout, HRTIMER_MODE_ABS); - - freezable_schedule(); - - ret = -ETIMEDOUT; - if (timo && !timeout.task) + if (!schedule_hrtimeout_range_clock(timo ? &timo : NULL, + tsk->timer_slack_ns, + HRTIMER_MODE_ABS, + tsk->umcg_clock)) { + ret = -ETIMEDOUT; break; + } } __set_current_state(TASK_RUNNING); - if (timo) { - hrtimer_cancel(&timeout.timer); - destroy_hrtimer_on_stack(&timeout.timer); - } - return ret; } @@ -515,7 +501,8 @@ void umcg_notify_resume(struct pt_regs * goto done; if (state & UMCG_TF_PREEMPT) { - umcg_pin_pages(); + if (umcg_pin_pages()) + goto die; if (umcg_update_state(tsk, UMCG_TASK_RUNNING, UMCG_TASK_RUNNABLE, &next_tid)) @@ -586,7 +573,9 @@ SYSCALL_DEFINE2(umcg_wait, u32, flags, u tsk->flags &= ~PF_UMCG_WORKER; /* see umcg_sys_{enter,exit}() */ - umcg_pin_pages(); + ret = umcg_pin_pages(); + if (ret) + return ret; ret = umcg_update_state(tsk, UMCG_TASK_RUNNING, UMCG_TASK_RUNNABLE, &next_tid); if (ret)