From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) (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 EA29E4F055C for ; Mon, 5 Oct 2026 17:17:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791220632; cv=none; b=tUiFO2TmcE6SFECOJHJ5EPKVhSRNlrt94Ervl0aRejtg4EhZWy/qb5BYFx6q8vdH5r9mOxAyISQoiScdiFY/ohBrbTlEdvSURCV8RFP5iH4eJEjCritnTZugK7s2FRs53eK8P+CZrWKWXGVlHtAstyBdBy9f7ZflPkRYiTahZPs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791220632; c=relaxed/simple; bh=qSkRi8XlT4WUuuM/Vrnlxa70Aiw5xHXCcH5kKxR3bV0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KKy2WNRkshtOSqXNnClRcFBclqmDRxNQjfuR4L+7abJV5rkyJVKgl87WBJdlqjIFu2PJw/Bk9E6WP+8ktafeaWdG+31QvgZGIXq4NV8L56JH1XgaIsiZGoYDBbCSl0EklL4lAklGe82cuqH7e5XVZjI9+rxqhwg+Q2cIbLT1snI= 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=UDY5pX8Y; arc=none smtp.client-ip=209.85.216.46 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="UDY5pX8Y" Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-398a5aad413so1423275a91.3 for ; Mon, 05 Oct 2026 10:17:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1791220629; x=1791825429; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Qdf2Dycggm4mT6sPheIXdhrke0YZJhuYFMLF05Xnp3s=; b=UDY5pX8Y9127n5mZ3eCQpMK+2Eb/GyskFPnWLkosnEfRkB48/zGqn1ylalApUYQLMm Pt86ZHW/upugrsf7s3sCYjo/OpTSW9lV7MmltEsvEUfzO23UHuzN9x+ocUL+QPedLrJc Nylw3S12DIWVZqkyhgp9ZQuMHfeMaQ+Rntw1liB6h3iU73x0eQ0TSre3/8xmiyJpWZQf I3qYvn4QMlafJ0KmKHgDEuUKJMdV9fNIsizbj2iq24Tm+COeESAJHRXAfTZ6zMWRo5Y+ 6hqYlH0UQU09e3UxdiVNyWEK7Ay21EVPyt9UiI+uAxkWZ+RfHkj1KoSocrrAqnA1/RAz 9TNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791220629; x=1791825429; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Qdf2Dycggm4mT6sPheIXdhrke0YZJhuYFMLF05Xnp3s=; b=0RkLNEncL5svLY2964WoaZETwWyYOvm3c3DJUrRHxbVgrzVR6GpiORhH8prD16SQyD ZryfgaFHSFlCaFUXZX6no1/ZqeBC3PQh+8H5QrXjd5tWo7PTnj3fLav0xrYjOxiCED0p aCay0C1r42t9YWE8PocaKB+MtH1g9ngGhSQ2X6sTpoSoxZ4dUEvrNONXkVWnrIemY1M6 kpGsLkhojD06HOPvTXJIYDg8G8fBmufjjB5+p1AlJGIhWYCcR14/p7Mlwboa74woo6wB k5SZLiEnpmdX0fpGh+uoxxCsfk67Oyq6ZfScaTji/X6DpAWDtZA3VXZnyw/xeDIHkdDx ASBA== X-Forwarded-Encrypted: i=1; AKwUvBy+Xy2YFHVE6Vs0EmkhtgTcTcThuEWi9O/AyBE1L7CTm9dCV6APv0lOA0onS/28MxMR6nCZ@lists.linux.dev X-Gm-Message-State: AFq9FYJ3cHAk8dbSxIN+KYTxE+A268KkHScsHbg9kQuNlPh1sMKoha3Y Z/TgKPnywWYEA+3l1YaewB2uIMhD7rVFtvLk13Zl3vUfgdiTPW00CEAh X-Gm-Gg: AYBFou0fdTCKaJpEF4qhr9B1YyZfihzUOg7x289Gg4llOmtyEp5hV6MAONdFuFKM1s6 Oi8DZ6V5JFPXpthnfUTUt0eROGpiotGq+6UFuDIQOCbr3SvjgF68aYmZbzpvRxyeJNynjg3nTK/ q903ktowP8rO+KttpaWXzGME5cvkPki9F6gzC5UiFubQ+uZ4aGp/T0XC2d9Pf3jP+TjWt5QV42V AdxSwRxtCg1qpbwzMkkYvClZrMpQLmCmKbA9VCvkkZB3AixesYQi+4dZnivMBpQ6oTep9Lh2v8U e4TF2xtwOyLyBXBQgptJMHP2vplVThdp1QOZWtj9Z1H+RS4QNy2LHDR99iPIyjkxcTMoXZK/thI tXL4IJ7hcaDOcPggFCzVprdaJjZ6MeR9nwyOMH6XrEYcyzM3Gs0IpVrPqJnmDk0f9Mpdm51Vld9 YOfOQ3uArLeVIA2tpWqJKL+7kKB1sXve9qBGzSCfOVWzf4JCJtiQz+bLDI8PUmcfD3Eck6gKd0D XBB2SJEd13V0o9zt6tDmNigAIGKpw== X-Received: by 2002:a17:90b:5870:b0:3a8:32f2:f4a5 with SMTP id 98e67ed59e1d1-3a832f2f5e2mr1648236a91.53.1791220628556; Mon, 05 Oct 2026 10:17:08 -0700 (PDT) Received: from kernel.tail6741c6.ts.net ([216.195.201.24]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3a853cafddesm406910a91.10.2026.10.05.10.16.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Oct 2026 10:17:08 -0700 (PDT) From: Kunwu Chan To: paulmck@kernel.org, corbet@lwn.net, mingo@redhat.com, frederic@kernel.org, neeraj.upadhyay@kernel.org, josh@joshtriplett.org, urezki@gmail.com, dave@stgolabs.net, lianux.mm@gmail.com Cc: stern@rowland.harvard.edu, parri.andrea@gmail.com, will@kernel.org, peterz@infradead.org, boqun@kernel.org, npiggin@gmail.com, dhowells@redhat.com, j.alglave@ucl.ac.uk, luc.maranget@inria.fr, akiyks@gmail.com, dlustig@nvidia.com, joelagnelf@nvidia.com, skhan@linuxfoundation.org, rdunlap@infradead.org, longman@redhat.com, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, jiangshanlai@gmail.com, qiang.zhang@linux.dev, kunwu.chan@gmail.com, brads@mainlining.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, lkmm@lists.linux.dev, linux-doc@vger.kernel.org, rcu@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH RFC v3 06/15] hazptr: elide redundant first drain pass Date: Tue, 6 Oct 2026 01:15:20 +0800 Message-ID: <20261005171529.1378809-7-kunwu.chan@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261005171529.1378809-1-kunwu.chan@gmail.com> References: <20261005171529.1378809-1-kunwu.chan@gmail.com> Precedence: bulk X-Mailing-List: lkmm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Each scan cycle drained both wildcard generations: the unpublished "other" generation (pass 1) and the pre-flip current generation (pass 2). Pass 1 is not needed for correctness, so flip the wildcard first and drain only the old generation while building the Bloom filter. An acquire that read the old wildcard before the flip may publish it into its slot after the drain has passed that slot. Such a straggling acquire cannot have loaded the pre-unpublish pointer; see the following LKMM test for the ordering argument. Signed-off-by: Kunwu Chan --- kernel/hazptr.c | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/kernel/hazptr.c b/kernel/hazptr.c index 799784f698ed..86336f229f57 100644 --- a/kernel/hazptr.c +++ b/kernel/hazptr.c @@ -365,24 +365,19 @@ static bool hazptr_scan_walk(void *watch, struct hazptr_bloom *bloom) } /* - * Wait until no per-CPU slot or overflow-list slot holds @wc. - * Callers must ensure that the wildcard value in use by new acquires - * differs from @wc, so that the set of slots holding @wc only - * shrinks, which guarantees forward progress. - */ -static void hazptr_drain_wildcard(void *wc) -{ - while (hazptr_scan_walk(wc, NULL)) - cond_resched(); -} - -/* - * Move pending waiters to ->scanning and perform a two-phase - * wildcard scan shared by all waiters. + * Move pending waiters to ->scanning, flip the wildcard, then + * drain the old generation while collecting observed addresses + * into the Bloom filter. New acquires use the new generation, + * so old-generation slots normally only drain. + * + * An acquire that read the old wildcard before the flip may + * publish it after the scanner has passed its slot, but cannot + * have loaded the pre-unpublish pointer. See + * Documentation/litmus-tests/hazptr/hazptr-wildcard-flip-escape.litmus. */ static void hazptr_scan_do_cycle(void) { - void *scan_wildcard, *old_wildcard; + void *old_wildcard; struct hazptr_waiter *w, *n; LIST_HEAD(done); @@ -397,16 +392,11 @@ static void hazptr_scan_do_cycle(void) return; } - /* Pass 1: drain the unpublished wildcard. */ - scan_wildcard = flip_wildcard(READ_ONCE(hazptr_wildcard)); - hazptr_drain_wildcard(scan_wildcard); - - /* Flip so new acquires use the new generation. */ - WRITE_ONCE(hazptr_wildcard, scan_wildcard); - old_wildcard = flip_wildcard(scan_wildcard); + old_wildcard = READ_ONCE(hazptr_wildcard); + WRITE_ONCE(hazptr_wildcard, flip_wildcard(old_wildcard)); /* - * Pass 2: drain the old wildcard while collecting observed + * Drain the old wildcard while collecting observed * addresses into the Bloom filter. */ while (hazptr_scan_walk(old_wildcard, &hazptr_scan.bloom)) -- 2.43.0