Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp1784602lqg; Mon, 4 Mar 2024 03:55:58 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUFdgz59D5EVxM2LNK5YqpOhEfbe5JoXLi3P8LOzpe+9ezUBBvOdlHVTiJ097lI1vVyOftBLNmdJinHftkAEX/P6B4qfAQe74tgtKQ+EQ== X-Google-Smtp-Source: AGHT+IEiNBBdW6JkdhLj88P+nkuQsAvw06k3A8hHDj3kLo61QBAudrZOC6F1csW1rxnbQ/2I68QM X-Received: by 2002:a05:6a20:324f:b0:1a1:479c:a9ca with SMTP id hm15-20020a056a20324f00b001a1479ca9camr2933539pzc.41.1709553357828; Mon, 04 Mar 2024 03:55:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709553357; cv=pass; d=google.com; s=arc-20160816; b=l2ugAIkjymhmT5SDiQ1uQQ6Z8cIEkBxqDfWHlTT7agWtK/F9OqQqgZj+cD1NsU3igF 46HQ6PmDpOzUw7AbtYA6jnfayzkW9Qa0lG/LI/KMaq5roAi9rZ+ogKqIKOKNuOEXYxBl wPNBy/AWnmcBQU48twoszNa09V1AMoLDOxSqwyh6YyQJ7JdDcJcy3N4KKS+zPHKqUx0y TkXZ/CUMNn/g02+95Ji3anLy4cLEAYBYM/il7LWbeiLl/xGmv9OpFvlGfKy1fN15K2ds 3jYCAkHvXZmHC2tTDgVZHV2HkP3XI8Au6Hr1gLpnGcDb3oxgigGbCGhkrHDQViijqZO0 vDMA== 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=PS3cTPCygm+91QOked8tijFIhJibCSo+Yn9LK1agimA=; fh=x5EVJoPG6ig7lfovOxVsbUIGy7PuVoTFc209eBD3IO8=; b=GbFdWydi27s8t9RvYBcxYoM5JVXd65B96/Y6wmWeK1iJzcop6EnQrLjyKFUOSmY9hE hSoO8lPPHAGI37Lrv5rPMVPdYmuzg8NXQSMXN5GnsJ2V8pPzKcMLInFiyScZ0LVc88lq mWkG38g2cw3oaSR+qeF11rjagSsQRxtbOnjLhqdNPzSqqCGH0VpGkpnNNaqDi70Y1hGL k6FLlx9gcYe8Q1wgvOKIxz6HDDS7DVD6okLCnRkveASROY/BY2FF6D5D6YrMUsgd/SxW iTqXHmNUJViZMygRLMElNIab8+LTl8Sy/GnN1df3b+rPfhQNHydF9TnG63D6YuwV4n/B 8zfw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BzaGLWZZ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-90537-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90537-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id jw7-20020a056a00928700b006e621f0739esi1639981pfb.379.2024.03.04.03.55.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 03:55:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-90537-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BzaGLWZZ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-90537-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90537-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 824EB282A3C for ; Mon, 4 Mar 2024 11:55:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AFC1F3B784; Mon, 4 Mar 2024 11:55:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BzaGLWZZ" 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 CBE763B189; Mon, 4 Mar 2024 11:55:50 +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=1709553350; cv=none; b=m/3w7VOr0hW7FiTep1aDERzvhnuzxFTJ6nwF+8WO3gi8L672ss0QXDsu16fSd0ZkFBvkHol/ipWgSu2c2RhM21R+TVnT7ji8kSon10IF1PzI2onhOzt3RCl0Zi2cSn1W3xpA5H9e82PF7TJ/af3sjyvFecGeIipe1IRZFJDhJcI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709553350; c=relaxed/simple; bh=C9l5GlIDwT57uW3nuT4SZmJxej662flcSTsn1taW6Yc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=JBc01izc2i/hpRqXyAqJuvFU1mJCb9/IVfiKFPwt9rY9arXgKYYObL36eGBAjNMkLam18neK2bddal9o+4y3Qki9XAtocx738ilFsd1oAj1bN1PnQSyabq/CGEXIeI1PSawgXgiWniKQbgAUZ/35z4N+WO4Oc3DsCEMUw+RuFVg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BzaGLWZZ; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id F10D5C433C7; Mon, 4 Mar 2024 11:55:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709553350; bh=C9l5GlIDwT57uW3nuT4SZmJxej662flcSTsn1taW6Yc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=BzaGLWZZeaomXtN8YrYSmmI70bToSfUpwLRoDuQ32TC4qFdcmEr3gC/CA4SwDVHes UtbioiU+g9iTbRLQXYCfS4gX8x4Bn3ukdFBnDO/ifdgd7J5D29VeEbHW/RTLP/PvcA rwdRZZ+vixU3EbjYGZT9X7zeFXn7KFjw9Z/vjksV74WpQTLoGWugXwboCmbLFuF+SZ mbEAGGuovjLS8sgROt5iIq2KlcZtHfmrxuveaTPt4WNhU+1G04a96/dvYLVsGwW+my bS97F7syfe4aCjxAiSXzDDxhoqMwYkynlwKjmtJxS6qOboJs+vMdIP6UXOoTw4dUCN skOsCFbc5uK5Q== Date: Mon, 4 Mar 2024 12:55:47 +0100 From: Frederic Weisbecker To: Uladzislau Rezki Cc: "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 Wed, Feb 28, 2024 at 07:04:21PM +0100, Uladzislau Rezki a ?crit : > On Tue, Feb 27, 2024 at 12:07:32AM +0100, Frederic Weisbecker wrote: > > On Tue, Feb 20, 2024 at 07:31:13PM +0100, Uladzislau Rezki (Sony) wrote: > > > +static void rcu_sr_normal_gp_cleanup_work(struct work_struct *work) > > > +{ > > > + struct llist_node *done, *rcu, *next, *head; > > > + > > > + /* > > > + * This work execution can potentially execute > > > + * while a new done tail is being updated by > > > + * grace period kthread in rcu_sr_normal_gp_cleanup(). > > > + * So, read and updates of done tail need to > > > + * follow acq-rel semantics. > > > + * > > > + * Given that wq semantics guarantees that a single work > > > + * cannot execute concurrently by multiple kworkers, > > > + * the done tail list manipulations are protected here. > > > + */ > > > + done = smp_load_acquire(&rcu_state.srs_done_tail); > > > + if (!done) > > > + return; > > > + > > > + WARN_ON_ONCE(!rcu_sr_is_wait_head(done)); > > > + head = done->next; > > > + done->next = NULL; > > > > 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) > > ... > > > > // A few more GPs later > > rcu_sr_normal_gp_init() { > > HEAD2 = rcu_sr_get_wait_head(); > > llist_add(HEAD2, &rcu_state.srs_next); > > // head == rcu_state.srs_next > > head = done->next; > > done->next = NULL; > > llist_for_each_safe() { > > // EXECUTE CALLBACKS TOO EARLY!!! > > } > > } > Looks like that. To address this, we should not release the head in the GP > > kthread. But then you have to unconditionally schedule the work, right? Otherwise the HEADs are not released. And that means dropping this patch (right now I don't have a better idea).