Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1972961rbb; Tue, 27 Feb 2024 07:02:43 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX709TMnCdYolmsM+B5ZKx/wLFWMGDqGCpYGCFPoyTtIlH/1hXNQf4ZtOh5cf0ukrXm11zecGKoLMHd1EUvXhoCC2iSlQOZnsQA6rWShw== X-Google-Smtp-Source: AGHT+IEbsdst2ilbDO4SnXTY0ca0b+J+ZpG8r7pOYhqsTo6Zt+6a/41J6zbxoSHaPVQifDCxV/W1 X-Received: by 2002:a17:90a:5d8a:b0:299:464c:c9fc with SMTP id t10-20020a17090a5d8a00b00299464cc9fcmr6532361pji.45.1709046163255; Tue, 27 Feb 2024 07:02:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709046163; cv=pass; d=google.com; s=arc-20160816; b=csUyGBZglRJVcoeG2AbgbhAmSfxqz1+4exQtMJLbc6fZ0HVofTLlZ5bXV0A1y9uzi1 IQNfpvEnH9ZwwB/GfIPqCcnDUSA9K9XeEVinsE7unxlor7oLV0CSRuQnX0c2Wp7w5Hj/ F7fDdQg7/qaR2pNEdMYaKP+dmT0EChFLffoqyNi+/3Lb/VaE3uj+HAolmQF9Zx91M1+7 XaQxMVrJAhTcGB5QZfDqCNbwRknKU8jdXdsH2RaD3t561XlJPWf8rgYkdr923R2Jxbf7 Al8erujMi8uvbYjhWWz141jUvwz2Bh+xDiZDIsy6XEoZxryH4Yf6hVp3ztn3Fb8RdIx/ RrqQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=VZsOqGsdaklucEaXXJHMGowufWc3p1n6zRbkSrF4bD8=; fh=aLvXR7lo0Yh4uym1NM3YqfJoXXhe4YtR7selwYkj0Io=; b=oZeMDA3SghH4+PHDRKG0I9U377m7Ikeg2jNb24ELNQ39zV/x/AafL5Ve77IUvrRpW3 9S2sRYsLlcOYCTzee+31Ak3BrRq6234d8d3+ycZwGuGAVle8LTWSPEOoJD1IutRjMAGn MtC0A5UZDquncjG2LIPsoS6j5Mo3SLnaDG9X+nM7NHsMavI9YOu5zV58WAhKix2Wh6rw j209/1oUHCtnUth6AqduMz+9ZPDvkOBU2wThcLg9EC/kSVQzZZc/6uuZXiz3yi7YenQt rhlzsBlSnfPgAi6qbtBUK2ymT6DkhJgcR8SphrvHbi2EbXavzZ+Xy17nbKf66kX3VCXt GhgQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="eyds4r/Z"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-83406-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83406-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id y6-20020a17090aa40600b0029a5678e1e0si5722995pjp.6.2024.02.27.07.02.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 07:02:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83406-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="eyds4r/Z"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-83406-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83406-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 46D0CB21F57 for ; Tue, 27 Feb 2024 14:37:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C6A2A13AA38; Tue, 27 Feb 2024 14:37:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eyds4r/Z" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB36817729; Tue, 27 Feb 2024 14:37:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709044650; cv=none; b=YbZOHU4kStzerV/yTtaxzuDMtMwcOawfsWXCe2ASWzb29Hvs7VNJxIN1H09eM1DV609GERm/eDTgMbzWsXlRYpxFqVaGBcGhu8mUSMDU77G0uk8Swt+AbnHEYy3pSnPLAF0tNKOOVUrlmy5Vx7qDgx5RLDCU0zKSlABLGZfyHsw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709044650; c=relaxed/simple; bh=1pmCi0aoLbtvh8q1FSw3S4VdL7lpSFQUAUvhYlx8DQE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MPSddEKMCbsxXEIjnlF3TRT/sbp67uKnoM2Knd+oNcNZlirbXAZbRNa/eh8yR4YMaZ5gjNRbj2xo7O5ZI7KFg5qnWanx0wunF6byc/Abfz998IwjgoxxZUCfnF7buRRLiDTIMBJjFNj1lGhecIxl4c4vSSIEF82IFPx0mSJVXco= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eyds4r/Z; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 115DCC433C7; Tue, 27 Feb 2024 14:37:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709044649; bh=1pmCi0aoLbtvh8q1FSw3S4VdL7lpSFQUAUvhYlx8DQE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=eyds4r/ZYIenIbutoup39KqYPbXB56SO2F35JRCZSjVTtSJxGVJG89S+bo9ql1XF2 W08OHAMv1vbpPB/mnDzZCIUMAmWgX5ouXBJFdErfqqHb6ynI42M8+CIKItR2UmTW78 aq5HXJIHAmBZJgfgWpMeLjma2znSWjbyhF63Gg/BldwGabFrL3vqba5PXIYFb5UakY i4CoHnfJLBnJkTc1OY3nUY6hRqllIPy1C2adpTQnQkujQt82AmJq3bUip9Fm+LEqUi wLWk+FHni3zxgl/5hHfhUu0fEZ8FYFkDFh7ELhLiDfxgyuEQioRTnYhnHR3/Plw8hJ cY5FAsZOqwOiw== Date: Tue, 27 Feb 2024 15:37:26 +0100 From: Frederic Weisbecker To: Z qiang Cc: "Uladzislau Rezki (Sony)" , "Paul E . McKenney" , RCU , Neeraj upadhyay , Boqun Feng , Hillf Danton , Joel Fernandes , LKML , Oleksiy Avramchenko Subject: Re: [PATCH v5 2/4] rcu: Reduce synchronize_rcu() latency Message-ID: References: <20240220183115.74124-1-urezki@gmail.com> <20240220183115.74124-3-urezki@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Le Tue, Feb 27, 2024 at 02:39:55PM +0800, Z qiang a ?crit : > > Can the following race happen? > > > > CPU 0 CPU 1 > > ----- ----- > > > > // wait_tail == HEAD1 > > rcu_sr_normal_gp_cleanup() { > > // has passed SR_MAX_USERS_WAKE_FROM_GP > > wait_tail->next = next; > > // done_tail = HEAD1 > > smp_store_release(&rcu_state.srs_done_tail, wait_tail); > > queue_work() { > > test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work) > > __queue_work() > > } > > } > > > > set_work_pool_and_clear_pending() > > rcu_sr_normal_gp_cleanup_work() { > > // new GP, wait_tail == HEAD2 > > rcu_sr_normal_gp_cleanup() { > > // executes all completion, but stop at HEAD1 > > wait_tail->next = HEAD1; > > // done_tail = HEAD2 > > smp_store_release(&rcu_state.srs_done_tail, wait_tail); > > queue_work() { > > test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work) > > __queue_work() > > } > > } > > // done = HEAD2 > > done = smp_load_acquire(&rcu_state.srs_done_tail); > > // head = HEAD1 > > head = done->next; > > done->next = NULL; > > llist_for_each_safe() { > > // completes all callbacks, release HEAD1 > > } > > } > > // Process second queue > > set_work_pool_and_clear_pending() > > rcu_sr_normal_gp_cleanup_work() { > > // done = HEAD2 > > done = smp_load_acquire(&rcu_state.srs_done_tail); > > > > // new GP, wait_tail == HEAD3 > > rcu_sr_normal_gp_cleanup() { > > // Finds HEAD2 with ->next == NULL at the end > > rcu_sr_put_wait_head(HEAD2) > > It seems that we should move rcu_sr_put_wait_head() from > rcu_sr_normal_gp_cleanup() to > rcu_sr_normal_gp_cleanup_work(), if find wait_head->next == NULL, invoke > rcu_sr_put_wait_head() to release wait_head. Well, rcu_sr_normal_gp_cleanup_work() already put all the wait heads that are _after_ srs_done_tail. But it can't put the srs_done_tail itself without introducing even worse races...