From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A83F41534E9 for ; Sat, 28 Sep 2024 23:13:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727565195; cv=none; b=pvF/X11qRsKhG8jvRfuxWEOVayuQmoW/ut+6UF/GE+CvM5q+OHgCNaM/9B2lxClpXm1SYqBKONFg2FzR5lAuSwig/6KaXzReLP3QQQ4C8+d+ctw/X4zBUNRF0n4AolAJly8sN5CcCbwpnOC5C9cFnuVUKOZRAM7rpP3D1aFMPHM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727565195; c=relaxed/simple; bh=xDhJtQezYDQhYGdc7LW28hqcUGAUnvcmud6T657Ut/E=; h=Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc: Message-Id:References:To; b=nK/oira+4BdWOA/1q9h56Hpm64MIKO7O0K3j+SZTo9d00oOBqMuma17QOfyO7Z3eojIkW9MKMm42ipfta7Lu9e94pPukywEY6dAj7gW2DpxXIloFPcT6eQuLiTTYqtGkf+2vk56jj+nwb8vF82aHOnxrkNLvnQTy1aVywl4dUiU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=SHJEdZV1; arc=none smtp.client-ip=209.85.214.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SHJEdZV1" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-2053525bd90so30709515ad.0 for ; Sat, 28 Sep 2024 16:13:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727565193; x=1728169993; darn=lists.linux.dev; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=hlXRms7F/yIYEZIpY96anVWqMAu7/hjyZTvOiryivSE=; b=SHJEdZV1Lt5Mk7ZXhOpV2zKz2bpmrDJ11VjF5L3LDT/dG5oz6IG1x/K4UuaVRuz8yB 9zk02HuePgekGngx1hvqb3NzG+nwOFAgLLTFU0MXBF1t4+3Anzu6wK8V+ZmcEH26eS7v riQeC/VMvT2wQW198+MncGMFeoQVK7gH+SEfmc4bNfwfTgkQfX81tiwzniOHWXs6x8Ho VVkNNzMja84ivrm9wA6iKo/Iv1VfRD65w9wO6SbDt0NHr3Sfo206J/cNYkmOPrLi8kGV aniBLNxpacYiHBjms+vFyEvNdU+ew9rsIyMaWCP4mSMIO9VkZGQQWIwaOtCxhytFMfTt xGlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727565193; x=1728169993; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hlXRms7F/yIYEZIpY96anVWqMAu7/hjyZTvOiryivSE=; b=YwzJ5uC/lLZLMtcxhUa8Sx7i2nqpYlrUAVe95EJomJEPypUaxOzDSFpvDEpktpbecW b3eWyVAGV6I2k4trAtjOtdvwK8ivd/bS6/2l7XyVGDmEL0QTnTj71dCjf2nrpmnX1+75 /qDiZED2ynMNWEzwy1Se0WhuzWcPqwuHtZNMU4POMwcQYr/Y2t5KSt9bTmjen2JNp6vG mOpTS93tsAeSP83XvkAKUrFPhPI9wECo7TMOHj+/3Y4xpEBjPhvrkXWTNtRN3KafRExt /pBjN4lZriQTgyc4FYikiEC03TlEnze9Ui+SaEPe+Effx04FD+jbqAom83CUpyUkq7DL nttA== X-Forwarded-Encrypted: i=1; AJvYcCVw6fEszJjlRFbmvItjijwBy+ZfetGaaJQ07O0AuHThLD7VW73ijlQ6sMMEeK/ykqdsSRSo@lists.linux.dev X-Gm-Message-State: AOJu0YwQwkDExDq6nnrisswh1r6RBYyfJ2YG9jAy3w6poa5ME9DD9391 kNQLN/tIknITOUUlG+eYbAQzFkeDNk4vOFX5s/mviWPbG0OxG9wp X-Google-Smtp-Source: AGHT+IE2sBYP1tAvZqMQRpXmx8wMXmRsA3LnUmxXborZPEfW+jZDkloOvwEfncz/nFiCQJfXofJTmQ== X-Received: by 2002:a17:902:d4c3:b0:20b:7731:e3f8 with SMTP id d9443c01a7336-20b7731e676mr1645985ad.26.1727565192698; Sat, 28 Sep 2024 16:13:12 -0700 (PDT) Received: from smtpclient.apple ([2402:d0c0:11:86::1]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20b37e0fa94sm31491515ad.135.2024.09.28.16.13.06 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Sep 2024 16:13:12 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Precedence: bulk X-Mailing-List: lkmm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3776.700.51\)) Subject: Re: [RFC PATCH 1/4] hazptr: Add initial implementation of hazard pointers From: Alan Huang In-Reply-To: <5F741990-7A14-4528-9AF8-817007689B0A@gmail.com> Date: Sun, 29 Sep 2024 07:12:53 +0800 Cc: Mathieu Desnoyers , Boqun Feng , Linus Torvalds , LKML , RCU , linux-mm@kvack.org, lkmm@lists.linux.dev, "Paul E. McKenney" , Frederic Weisbecker , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , "Uladzislau Rezki (Sony)" , Steven Rostedt , Lai Jiangshan , Zqiang , Peter Zijlstra , Ingo Molnar , Will Deacon , Waiman Long , Mark Rutland , Thomas Gleixner , Kent Overstreet , Vlastimil Babka , maged.michael@gmail.com, Neeraj upadhyay Content-Transfer-Encoding: quoted-printable Message-Id: References: <4167e6f5-4ff9-4aaa-915e-c1e692ac785a@efficios.com> <48992c9f-6c61-4716-977c-66e946adb399@efficios.com> <2b2aea37-06fe-40cb-8458-9408406ebda6@efficios.com> <55633835-242c-4d7f-875b-24b16f17939c@huaweicloud.com> <62508c1f-66ca-450d-abb6-236ca3b9096d@huaweicloud.com> <4ed833df-54e6-454a-ab1a-73967cc51054@huaweicloud.com> <5F741990-7A14-4528-9AF8-817007689B0A@gmail.com> To: Jonas Oberhauser X-Mailer: Apple Mail (2.3776.700.51) 2024=E5=B9=B49=E6=9C=8829=E6=97=A5 06:10=EF=BC=8CAlan Huang = wrote=EF=BC=9A >=20 > 2024=E5=B9=B49=E6=9C=8828=E6=97=A5 06:18=EF=BC=8CJonas Oberhauser = wrote=EF=BC=9A >>=20 >>=20 >>=20 >> Am 9/27/2024 um 10:10 PM schrieb Mathieu Desnoyers: >>> On 2024-09-27 21:23, Jonas Oberhauser wrote: >>> [...] >>>> That idea seems to be confirmed by this (atrocious, not to be = copied!) example: >>>>=20 >>>> int fct_escape_address_of_b(void) >>>> { >>>> int *a, *b; >>>>=20 >>>> do { >>>> a =3D READ_ONCE(p); >>>> asm volatile ("" : : : "memory"); >>>> b =3D READ_ONCE(p); >>>> } while (a !=3D b); >>>>=20 >>>> // really really hide b >>>> int **p =3D &b; >>>> OPTIMIZER_HIDE_VAR(p); >>>>=20 >>>> asm volatile ("" : : : "memory"); >>>> return *b; >>>> } >>>>=20 >>>> This also does not generate any additional instructions, unlike = just using OPTIMIZER_HIDE_VAR(b). >>>>=20 >>>> What is the advantage of defining OPTIMIZE_HIDE_VAR the way it = currently works instead of like above? >>> Did you try it on godbolt.org ? Does it have the intended effect ? >>=20 >> I certainly did try and certainly read it as having the intended = effect, otherwise I wouldn't have written that it seems confirmed. >>=20 >> However, just because my eyes read it doesn't mean that's what = happened, and even if it happened doesn't mean that it is guaranteed to = happen. >>=20 >>> By the looks of it, you're just creating another version of @b = called >>> "p", which is then never used and would be discarded by further >>> optimization. > >>> I'm unsure what you are trying to achieve here. >>=20 >> Simply put I'm trying to let the compiler think that I leaked the = address of b. After that, the memory barrier should let it think that = the b after the memory barrier might not be the same as the one before = it (which was equal to a), forcing it to read from b. >>=20 >> However, I suppose on second thought that that might not be enough, = because the compiler could still simply do b =3D a right after exiting = the while loop. >>=20 >> And that is true no matter what we put behind the while loop or = before the condition, as long as the condition compares a and b, right = after it the compiler can do b =3D a. Just took me a while to see :)) >>=20 >> I'm not sure why gcc does the b=3Da with the normal = OPTIMIZER_HIDE_VAR but (as far as I read the code) doesn't do it with = the above. Maybe just a weird corner case... >=20 > Let the p to be a static variable out of the function will make a = difference. >=20 > Or the following: >=20 > int **p =3D &b; > barrier_data(p); Or the following: int **t =3D &b; WRITE_ONCE(t, &b); barrier(); return *b; also works. >=20 > also works. >=20 > BTW, barrier_data(&b) generates more instructions than godbolt when = build the kernel. >=20 >>=20 >> Have fun, >> jonas