Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1142780ybl; Sat, 18 Jan 2020 19:50:36 -0800 (PST) X-Google-Smtp-Source: APXvYqxM7W9lGDQt7KJpEFaEtK/yRf0J0O8tTtgs47yi8rYR9g4dBGbFXvNnELcHTKMDB0BG7bzU X-Received: by 2002:a9d:6f82:: with SMTP id h2mr11544451otq.69.1579405836185; Sat, 18 Jan 2020 19:50:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579405836; cv=none; d=google.com; s=arc-20160816; b=BFeRJntYCWVbKapVl9s2NmLlMmVWb+05W+7r0YWp1oU2GkXBIQLgt7f+Tc/3YD6PKl ZlDpEKMZXqqJUYCF2e862GxVkhncuEqa4EPFT9gMs8lh26DrKztuwoAl3TGe5/b0I7i0 WTjp6go7ItJMtTykc/5o9i0/yVRF3HZCCz5ENZhpHEijoQfN6jH2+CkUdTmzVqwKgjdt tOAmzetqXPyzErYuKcDu1nXBjpQxpBqdr1d7ajKtwjAf+6bSCiiJY45JdC5lBZVXcjy0 ogp6kFiDF9H97nhHzMQKr33f/i0s9feOxb7dndXLJ0kXl9/B87HM8MT1Xu4zZOkkiEWd mk5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject; bh=xygWVBWR7uGh2cqAAODBV8wuwuWeE9BF4YbU24F8Avc=; b=XIqjEhlRW1hkYfobocBwL2bwssPZmby+dbHRvNfF3x/MLNPEa6ckcir8zmemx0yXeT 0EXn2/Rf2gZWWDG0Elo8ce++c7N0cKYGeA/CpSYQtegBvL18vgOaG7bnrUN06oL7Wk5m lBdUPYVctqUwyXYtAYyv2/iYqb0awA4uWFHE/J2mLw6kON3iXOuKOTa/yt/EN7G/10G8 lt6UcSMZuLFKeJAddeRSXGouBp5TMyBSFnm8TPp6L3S173fgHro6sB8Wl5SXPo18FKCO 7TsPvqbL3WZRcCmF6rv9DiQ84ffBoNCLiI9zfGNdtrqpICTThbrhoP+Pp5W4x8bzqh9J uGhg== ARC-Authentication-Results: i=1; mx.google.com; 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 l78si16431169oih.182.2020.01.18.19.50.24; Sat, 18 Jan 2020 19:50:36 -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; 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 S1726587AbgASDqg (ORCPT + 99 others); Sat, 18 Jan 2020 22:46:36 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:9662 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725980AbgASDqf (ORCPT ); Sat, 18 Jan 2020 22:46:35 -0500 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 1685B544BA0FA4AD7BD8; Sun, 19 Jan 2020 11:46:34 +0800 (CST) Received: from [127.0.0.1] (10.74.221.148) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.439.0; Sun, 19 Jan 2020 11:46:23 +0800 Subject: Re: [PATCH] net: optimize cmpxchg in ip_idents_reserve To: Peter Zijlstra References: <1579058620-26684-1-git-send-email-zhangshaokun@hisilicon.com> <20200116.042722.153124126288244814.davem@davemloft.net> <930faaff-4d18-452d-2e44-ef05b65dc858@gmail.com> <1b3aaddf-22f5-1846-90f1-42e68583c1e4@gmail.com> <430496fc-9f26-8cb4-91d8-505fda9af230@hisilicon.com> <20200117123253.GC14879@hirez.programming.kicks-ass.net> CC: Eric Dumazet , David Miller , , , , , , , , Will Deacon From: Shaokun Zhang Message-ID: <5fd55696-e46c-4269-c106-79782efb0dd8@hisilicon.com> Date: Sun, 19 Jan 2020 11:46:23 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 MIME-Version: 1.0 In-Reply-To: <20200117123253.GC14879@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.74.221.148] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Peter, On 2020/1/17 20:32, Peter Zijlstra wrote: > On Fri, Jan 17, 2020 at 02:54:03PM +0800, Shaokun Zhang wrote: >> So how about this? ;-) >> >> delta = prandom_u32_max(now - old); >> >> +#ifdef CONFIG_UBSAN >> /* Do not use atomic_add_return() as it makes UBSAN unhappy */ >> + old = (u32)atomic_read(p_id); >> do { >> - old = (u32)atomic_read(p_id); >> new = old + delta + segs; >> - } while (atomic_cmpxchg(p_id, old, new) != old); >> + } while (!atomic_try_cmpxchg(p_id, &old, new)); >> +#else >> + new = atomic_add_return(segs + delta, p_id); >> +#endif > > That's crazy, just accept that UBSAN is taking bonghits and ignore it. > Use atomic_add_return() unconditionally. We have used the atomic_add_return[1], but it makes the UBSAN unhappy followed by the comment. It seems that Eric also agreed to do it if some comments are added. I will do it later. Thanks, Shaokun [1] https://lkml.org/lkml/2019/7/26/217 > > . >