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 62675C433F5 for ; Wed, 24 Nov 2021 21:42:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C2FAE6B0075; Wed, 24 Nov 2021 16:42:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BDFA36B0078; Wed, 24 Nov 2021 16:42:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A80876B007B; Wed, 24 Nov 2021 16:42:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0185.hostedemail.com [216.40.44.185]) by kanga.kvack.org (Postfix) with ESMTP id 95DD96B0075 for ; Wed, 24 Nov 2021 16:42:10 -0500 (EST) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 59B2A8D6EF for ; Wed, 24 Nov 2021 21:42:00 +0000 (UTC) X-FDA: 78845146716.27.0502626 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf03.hostedemail.com (Postfix) with ESMTP id C6AB03000444 for ; Wed, 24 Nov 2021 21:41:56 +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=AtyATGG4/Tqtkd6LyCLZuHtGU7V1I4VQuaKYnkFLL2A=; b=mIJKySH7od+fNxhERGhQpBaGly FyK5+VivZ/jRfp26y9Iff67t1ZsvpmrnizxuoOn1J4kX0Y9mkLfvLy3Hc4PPH3g9p64328Hy7OqDN ASjCfl+IvmiRQV51fSkr9bJceFTzxCNYFDafRjSB0EOwV3vojfyg3hkFMF9xvREuqG19M4NR3plct bG9lPglbpes3e9Y/dLV4035pQaf9MM5bUO9jE271bmSmmIvgL6mSEdasD22n9h+OmhCedNEtZlIoP WiY8rEWD2hB1C6LiwNDTTqDa/wiNf4U+dMKL5vYZqllgLjUmGWlovgcOqB3BoeL7Ose90SEuxjMqc Tewcst5Q==; 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 1mq01Y-000JzV-De; Wed, 24 Nov 2021 21:41:52 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id F2D71986843; Wed, 24 Nov 2021 22:41:51 +0100 (CET) Date: Wed, 24 Nov 2021 22:41:51 +0100 From: Peter Zijlstra To: Peter Oskolkov Cc: Ingo Molnar , Thomas Gleixner , Andrew Morton , Dave Hansen , Andy Lutomirski , linux-mm@kvack.org, linux-kernel@vger.kernel.org, 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: <20211124214151.GH721624@worktop.programming.kicks-ass.net> References: <20211122211327.5931-1-posk@google.com> <20211122211327.5931-4-posk@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211122211327.5931-4-posk@google.com> X-Rspamd-Queue-Id: C6AB03000444 X-Stat-Signature: op5imia4ozh3fbpr8k4s8wezhrfa9ke1 Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=mIJKySH7; dmarc=none; spf=none (imf03.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org X-Rspamd-Server: rspam02 X-HE-Tag: 1637790116-448579 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 Mon, Nov 22, 2021 at 01:13:24PM -0800, Peter Oskolkov wrote: > + while (true) { (you have 2 inf. loops in umcg and you chose a different expression for each) > + u64 umcg_state; > + > + /* > + * We need to read from userspace _after_ the task is marked > + * TASK_INTERRUPTIBLE, to properly handle concurrent wakeups; > + * but faulting is not allowed; so we try a fast no-fault read, > + * and if it fails, pin the page temporarily. > + */ That comment is misleading! Faulting *is* allowed, but it can scribble __state. If faulting would not be allowed, you wouldn't be able to call pin_user_pages_fast(). > +retry_once: > + set_current_state(TASK_INTERRUPTIBLE); > + > + /* Order set_current_state above with get_user below. */ > + smp_mb(); And just in case you hadn't yet seen, that smp_mb() is implied by set_current_state(). > + ret = -EFAULT; > + if (get_user_nofault(umcg_state, &self->state_ts)) { > + set_current_state(TASK_RUNNING); > + > + if (pinned_page) > + goto out; > + else if (1 != pin_user_pages_fast((unsigned long)self, > + 1, 0, &pinned_page)) That else is pointless, and that '1 != foo' coding style is evil. > + goto out; > + > + goto retry_once; > + } And, as you could've seen from the big patch, all that goto isn't actually needed here, break / continue seem to be sufficient. > + > + if (pinned_page) { > + unpin_user_page(pinned_page); > + pinned_page = NULL; > + }