Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp369834imu; Fri, 11 Jan 2019 01:47:04 -0800 (PST) X-Google-Smtp-Source: ALg8bN6qrG16B0qMkW1MeO7hDIuT7ZJXh6X3bG4ZmgJSHUR9762whwopsVakT8Iw9uaSF3auFFao X-Received: by 2002:a17:902:8a95:: with SMTP id p21mr14297656plo.183.1547200024115; Fri, 11 Jan 2019 01:47:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547200024; cv=none; d=google.com; s=arc-20160816; b=Bo999HECSFjEWXI/OCzffI7Rlw433fakUp0ZvXo3m8Sb0YbZKv/OLCt/qZrpeGNesk O1hWq3UvFZp7KoatdmWPCV+26ntDM2oj0T9xt2RUxNvPKk2XfYzdbPUWfRNCHgGMsc2g oApv6V4rSEQUCqlLKJbB+IhRzqKEhI7jj2QNSj0qKgzdRPOofkO5dpWlmPuGkBZSK7n/ 4MRBQm53xpZ5X7liJ2vHfbw+HCt7g1Ls7vZBKgyt0CPA4U10rQZ8vXp+3fZlJVrOHTA4 XQxiEWUP7U39v2CEwG1/e2QY9WPElj4ceMcFwQGgvyhX2lVhGCM5omk1iialwIkyXNE5 CfuA== 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; bh=3bbqLmoBi4UZeRgd7URqMZLeNNe0MRIllp1E7eJVj0A=; b=K6EiWQeteKInASePkzs5s3nZUFSXxWpyle3p3p6b0+1/mgwi8hnIlDafQFH9m1vxdH yRoowp2cNku2af78xqm9gr4whc/w2DlhX4h1b5fcVAfZoewcK6Vi8K7p3AcnXFoWEpm2 hJzQmUSSNfh18FEovr1b0Ubt+uVEFOriBQPjIFenat15PLinC0fi/Vajxqhf4355Mqyi Xm+4YcgRIPxd36LuPEeHt66Q1nuPB21BRORXIHmkP6AQWXMmehnmRFWN0yiZoNdfiWep ut6EtZe+a3iYrdjzf0hNPoGoQcAP2SbzPv8yesPoPK9MT05EplRW6yHw4l+eihWs4HJC AXcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=aNNmoPgs; 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 i129si81614608pfb.32.2019.01.11.01.46.48; Fri, 11 Jan 2019 01:47:04 -0800 (PST) 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=merlin.20170209 header.b=aNNmoPgs; 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 S1730200AbfAKJY0 (ORCPT + 99 others); Fri, 11 Jan 2019 04:24:26 -0500 Received: from merlin.infradead.org ([205.233.59.134]:55972 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727900AbfAKJY0 (ORCPT ); Fri, 11 Jan 2019 04:24:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.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=3bbqLmoBi4UZeRgd7URqMZLeNNe0MRIllp1E7eJVj0A=; b=aNNmoPgsvxPQq61hvQHcor5bA 0LPvTkpfJ/6vOrRplQ7yTmX6+sHt2N1cWHPnoOkQSHh3hLqzc42ktWwk0XLRarfTDjZu5OTX3AAHw 8YCHrml7NksXzKYP3YveERj9LXQ7LXne8iSuMkUO+2vpSDvjva6FGxIVM6THVUB0dVUNsnWkYhwf0 Ks4R4+UanUuhAxT44qHB5eDVc/s4RSPENGw1HZ55p/2fv8EULhstdSmm4GcAE7SjgVxe9YqbP56PC htjUC7aAGNucsLsqRxRbT8D1j8vJ4Bd22ffdBVeRCu9PezulCN7pMKumK2iS1mKHE+Iz772bm3UNq iZef46nvA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1ght2v-00080C-Nu; Fri, 11 Jan 2019 09:24:09 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 80185208096AB; Fri, 11 Jan 2019 10:24:08 +0100 (CET) Date: Fri, 11 Jan 2019 10:24:08 +0100 From: Peter Zijlstra To: Vineet Gupta Cc: linux-kernel@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-mm@kvack.org, Miklos Szeredi , Ingo Molnar , Jani Nikula , Chris Wilson , Andrew Morton , Will Deacon , Mark Rutland Subject: Re: [PATCH 3/3] bitops.h: set_mask_bits() to return old value Message-ID: <20190111092408.GM30894@hirez.programming.kicks-ass.net> References: <1547166387-19785-1-git-send-email-vgupta@synopsys.com> <1547166387-19785-4-git-send-email-vgupta@synopsys.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1547166387-19785-4-git-send-email-vgupta@synopsys.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 10, 2019 at 04:26:27PM -0800, Vineet Gupta wrote: > @@ -246,7 +246,7 @@ static __always_inline void __assign_bit(long nr, volatile unsigned long *addr, > new__ = (old__ & ~mask__) | bits__; \ > } while (cmpxchg(ptr, old__, new__) != old__); \ diff --git a/include/linux/bitops.h b/include/linux/bitops.h index 705f7c442691..2060d26a35f5 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h @@ -241,10 +241,10 @@ static __always_inline void __assign_bit(long nr, volatile unsigned long *addr, const typeof(*(ptr)) mask__ = (mask), bits__ = (bits); \ typeof(*(ptr)) old__, new__; \ \ + old__ = READ_ONCE(*(ptr)); \ do { \ - old__ = READ_ONCE(*(ptr)); \ new__ = (old__ & ~mask__) | bits__; \ - } while (cmpxchg(ptr, old__, new__) != old__); \ + } while (!try_cmpxchg(ptr, &old__, new__)); \ \ new__; \ }) While there you probably want something like the above... although, looking at it now, we seem to have 'forgotten' to add try_cmpxchg to the generic code :/