Received: by 10.213.65.68 with SMTP id h4csp1506726imn; Thu, 15 Mar 2018 01:20:15 -0700 (PDT) X-Google-Smtp-Source: AG47ELuT4Fh6jr1EoKuLsnLjEfUwpvjB3w1oyz4YU8Q2Jgg9LFeMClsWbE+/02Rr6LAdA+JlKCv1 X-Received: by 2002:a17:902:4201:: with SMTP id g1-v6mr7215407pld.62.1521102015046; Thu, 15 Mar 2018 01:20:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521102015; cv=none; d=google.com; s=arc-20160816; b=R3/KgZ0nXuEVxLn+uW5o3e0dX9pM9xNrmyjS0GME4vUwfg+S7fCamHX6jgnqor9j6x wJjBv+5F6Yod7LDzihfToybFTBgR/0BqubLYhYrL/4Dt/vhI13ZMYDzndImXlyZll+p1 haI1fOZNCElk8mU+5AWhRwLeSnZu4eA12HHINUxmYII9AE7L5I4jg90hutvSgg6laUPS 6iqEya6EADhjVxhdjORt6OWk1X4roZ1KWR3evJXNFBdAMx/VQoIFgVHnOcQXSISqNWv8 MHhQtnquIiua+BLcHkXtN8MX0IFn9HdpdnOjaCHrNzEeq3V/82U4dhnkOdxU5A8CdYNb 3qlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=Qg7WBrKJ0ZQ7f1O/h56NJTKvirMCUjeJfseJJfj37Yk=; b=0WY7Y8wgDdFQ86Lr0RtZPGOQD1GWfJA3ez+sp7N8cn8yUdUZTPLg/s6M7xqKqiNmsl nR1vmoKppojXukQQ5dOGxJAzXBvqWmHfkvDGzYqc0Mb7JTh7XPqwYb9u8Ys4XOVfocKi dWU0rq32pTjkSXWiZ55DB0XBfrnFFhmQ/xkqhAsVfSfbGABz8yKPibHFLOwH8j2RuiEk MLWT2DGH2Xw0AXA5YbmVjACXMWeQtG+E3zTKy7gW40DUJQiAtQoiJCZF8dDjiRQ4Z59H Mr971pcn0kW9O5vBHfcRA33u5S+7gU8PkarEHAj/oe/0ogtskR8YfekpFmQuqYbAAF0U kJNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=LFYCWZCi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z62si3110879pgd.819.2018.03.15.01.20.00; Thu, 15 Mar 2018 01:20:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=LFYCWZCi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751542AbeCOISw (ORCPT + 99 others); Thu, 15 Mar 2018 04:18:52 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:33472 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750740AbeCOISt (ORCPT ); Thu, 15 Mar 2018 04:18:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.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:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Qg7WBrKJ0ZQ7f1O/h56NJTKvirMCUjeJfseJJfj37Yk=; b=LFYCWZCiiXFEf26WZjhWx7zQ9 e6UuGVR87hUgkjjj+aPu+xfde+gQQpCUoQH37/RlWOasPSn99XeRxQ17N11JFVrCLcHyOKdbk1EvI VRZ5dNoelMHoS0wcU9Q555ZPWwGixnUGRgDdrX30RoFvzWATqFrYS21O6jcqsBLGBS7q4EF1Sf4qO vphxj5HoQZf+mpfMGGPRRmFY4sqysle9QMj22WBrum0S0V0/j8r3B6dkCZiJz6u3MI2ngACcsXN0W MCJFRGOMnSVIK02cSXWjHA4frMnUsrTinYvxGQBLfk4h2n8JiQCRtMzOt2IhPpowjk+zcGj319Afx cl1r6QoTw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1ewO64-0005dw-FM; Thu, 15 Mar 2018 08:18:48 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id C35A92029F869; Thu, 15 Mar 2018 09:18:45 +0100 (CET) Date: Thu, 15 Mar 2018 09:18:45 +0100 From: Peter Zijlstra To: Alexey Brodkin Cc: "Vineet.Gupta1@synopsys.com" , "linux-kernel@vger.kernel.org" , "linux-arch@vger.kernel.org" , "linux-snps-arc@lists.infradead.org" Subject: Re: arc_usr_cmpxchg and preemption Message-ID: <20180315081845.GS4064@hirez.programming.kicks-ass.net> References: <1521045375.11552.27.camel@synopsys.com> <20180314175352.GP4064@hirez.programming.kicks-ass.net> <1521059931.11552.51.camel@synopsys.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1521059931.11552.51.camel@synopsys.com> User-Agent: Mutt/1.9.3 (2018-01-21) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 14, 2018 at 08:38:53PM +0000, Alexey Brodkin wrote: > > int sys_cmpxchg(u32 __user *user_ptr, u32 old, u32 new) > > { > > u32 val; > > int ret; > > > > again: > > ret = 0; > > > > preempt_disable(); > > val = get_user(user_ptr); > > if (val == old) > > ret = put_user(new, user_ptr); > > preempt_enable(); > > > > if (ret == -EFAULT) { > > struct page *page; > > ret = get_user_pages_fast((unsigned long)user_ptr, 1, 1, &page); > > if (ret < 0) > > return ret; > > put_page(page); > > goto again; > > I guess this jump we need to do only once, right? Typically, yes. It is theoretically possible for the page to get paged-out right after we do put_page() and before we do get/put_user(), But if that happens the machine likely has bigger problems than having to do this loop again. FWIW, look at kernel/futex.c for working examples of this pattern, the above was written purely from memory and could contain a fail or two ;-) Also, it might make sense to stuff this implementation in some lib/ file somewhere and make all platforms that need it use the same code, afaict there really isn't anything platform specific to it.