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 1F3C0C369D0 for ; Wed, 25 Sep 2024 11:37:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9436C6B0099; Wed, 25 Sep 2024 07:37:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8F3876B009A; Wed, 25 Sep 2024 07:37:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7BB026B009B; Wed, 25 Sep 2024 07:37:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 5CE8C6B0099 for ; Wed, 25 Sep 2024 07:37:41 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 0D2551204DC for ; Wed, 25 Sep 2024 11:37:41 +0000 (UTC) X-FDA: 82603060722.14.DCC8A08 Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) by imf11.hostedemail.com (Postfix) with ESMTP id 3395D40018 for ; Wed, 25 Sep 2024 11:37:39 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=efficios.com header.s=smtpout1 header.b=NzUR10xe; dmarc=pass (policy=none) header.from=efficios.com; spf=pass (imf11.hostedemail.com: domain of mathieu.desnoyers@efficios.com designates 167.114.26.122 as permitted sender) smtp.mailfrom=mathieu.desnoyers@efficios.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727264161; a=rsa-sha256; cv=none; b=h8dXW6AiqPl7BNGXEbdQF45iHRqXKMAXAqPJrC8RdcfSDznSqLBNgv+GgZB97CCDL24MwP AI8ge2OLYw+9VAtQTYYA2km+Bz6zwoWnUvBPlJxXooWvgBaH5fn3ucjvPzZGczkdtW8RFz WJxnoIJPtYAlTFXVTJGUoXcUuQlDsvs= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=efficios.com header.s=smtpout1 header.b=NzUR10xe; dmarc=pass (policy=none) header.from=efficios.com; spf=pass (imf11.hostedemail.com: domain of mathieu.desnoyers@efficios.com designates 167.114.26.122 as permitted sender) smtp.mailfrom=mathieu.desnoyers@efficios.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727264161; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=2sb23Wf6ryuqcduOaV9uwY0tC2Z4v2qaHwzTbHQVock=; b=W4aMhA0iz6zOjqOo2qS6ZJy0Fx873MSoZdXMY3PLIP4PtAEyQhTvyCExRs2nhsrHusf1VL vdZBz6Zvh8CunyZlpAb9Jf54X7YvY6rXzQ3i9oUPfnpWPYv7ozAc2OnugOzr0GUnS9MZwg XGRTcdEh7ZuX4IyLnAgtu0ZbySrBqRM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1727264258; bh=mNVhvWOEn6bEbyXBRFPt8xXjd1N12QiImpkDDnCHGZg=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=NzUR10xe39M7KcplzFnp+pUsEnYBTpuWdGy3vbCLCSkWSGx7UPd4EO5CiQnCY1JYv JtRxX5/Ixr7OvlSMQIatUb49kBUW3RitX8UtpVMisU2jOeRGePJAlTKFYsM9DatxiC i6QageZOCnVC23DGwUXJfVSZG3TkO7GsMJitiSGz5o3khKYim3JA9CZgkBj4oyP6Bh r4K6hqSj61MhTBA4aXhIbWOuA1mN4pMErKQ29tuxB+3hbN3+GUh2dqogU9ky+12xgT wgQOr4BhV3FzutJAbY057deM4ZjVSuYufhlTHd+ecR9QhWlEcFwcK6EQMFnb6BbooY PUPJVGFPX6eHQ== Received: from [192.168.126.112] (unknown [147.75.204.251]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4XDF885PTZz1LfT; Wed, 25 Sep 2024 07:37:28 -0400 (EDT) Message-ID: <38b04b86-1e85-40f0-8174-3c8ab29cbcaf@efficios.com> Date: Wed, 25 Sep 2024 13:36:47 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH 1/1] hpref: Hazard Pointers with Reference Counter To: Jonas Oberhauser , Boqun Feng , "Paul E. McKenney" Cc: linux-kernel@vger.kernel.org, Will Deacon , Peter Zijlstra , Alan Stern , John Stultz , Linus Torvalds , Frederic Weisbecker , Joel Fernandes , Josh Triplett , Uladzislau Rezki , Steven Rostedt , Lai Jiangshan , Zqiang , Ingo Molnar , Waiman Long , Mark Rutland , Thomas Gleixner , Vlastimil Babka , maged.michael@gmail.com, Mateusz Guzik , rcu@vger.kernel.org, linux-mm@kvack.org, lkmm@lists.linux.dev References: <20240921164210.256278-1-mathieu.desnoyers@efficios.com> <48ae741e-98aa-49d9-b677-6c4f8fd1bcb0@efficios.com> <07c9285f-44a1-486a-8390-0c63cefae35a@huaweicloud.com> From: Mathieu Desnoyers Content-Language: en-US In-Reply-To: <07c9285f-44a1-486a-8390-0c63cefae35a@huaweicloud.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 3395D40018 X-Stat-Signature: kqfebir3r63gundofchxcw6tqntgaun4 X-Rspam-User: X-HE-Tag: 1727264259-863169 X-HE-Meta: U2FsdGVkX1+wuHKaa86zji6x4UGQET/rL0ZMHSOQlQlwj2N9ytQZoh0hzX8yjcki6g4MkOPSG6PDNNHBQXvR9UdATeY0XP0no9BLUkjN+mPRe4rXRsm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0jFwvc65pgSI7d8FdkP6l/ym43mrntXg97KvjA4sAnTWAH/VMDp0dvmmmRa70MFbzZb8/esfQhBarU+uNbEplKfGfJmE4LxqdpfC6HNUq5QEw34gLKcvjD0bgKEpTPghIJVxCB2QaSmgYcqffSVEyLnfpR26Tmt5PW13QNWynBXNm3avs4QDHkKZzXvp5auzmPjdwg+Y02wK3YtVcZspIbjhOqfW1uQp10AIRZn/YfSWCU28lHX+IEQ= 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: List-Subscribe: List-Unsubscribe: On 2024-09-25 12:06, Jonas Oberhauser wrote: > > > Am 9/25/2024 um 8:35 AM schrieb Mathieu Desnoyers: >> On 2024-09-25 07:57, Jonas Oberhauser wrote: >>> Hi Mathieu, > >>> I haven't read your code in detail but it seems to me you have an ABA >>> bug: as I explained elsewhere, you could read the same pointer after >>> ABA but you don't synchronize with the newer store that gave you >>> node2, leaving you to speculatively read stale values through *ctx->hp. >>> (I am assuming here that ctx->hp is essentially an out parameter used >>> to let the caller know which node got protected). >> >> The following change should fix it: >> >>       cmm_barrier(); >> -    node2 = uatomic_load(node_p, CMM_RELAXED);    /* Load A */ >> +    node2 = rcu_dereference(*node_p);    /* Load A */ >> > > I don't think this fixes it, because IIRC rcu_dereference relies on the > address dependency (which we don't have here) to provide ordering. > > I would recommend either: > > -    ctx->hp = node; > +    ctx->hp = node2; > > which fixes the problem under the perhaps too weak assumption that the > compiler doesn't use its knowledge that node==node2 to just undo this > fix, or more strictly, As stated in Documentation/RCU/rcu_dereference.rst from the Linux kernel, comparing the result of rcu_dereference against another non-NULL pointer is discouraged, as you rightly point out. > > +    ctx->hp = READ_ONCE(node2); > > which I believe makes sure that the value of node2 is used. I am not entirely sure this extra READ_ONCE() would be sufficient to prevent the compiler from making assumptions about the content of node2 and thus use the result of the first load (node) instead. It would also not suffice to prevent the CPU from speculatively using the result of the first load to perform dependent loads AFAIU. > Alternatively you could always use an acquire load. Unless someone comes up with a sound alternate approach, I am tempted to go with an acquire load as the second load within hpref_hp_get(). This way, the compiler would not attempt to use the node value from the first load for dependent loads, and the and CPU won't try to speculate dependent loads either. Thanks, Mathieu > > > Best wishes, > >   jonas > -- Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com