Received: by 2002:a05:7208:d055:b0:7f:33c7:ddb6 with SMTP id y21csp496928rba; Wed, 28 Feb 2024 10:04:36 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUsf8KvApQgxB6OPnQeJfBc9Jvbj4peFZyadScyKjQfwmfkX44AmRtGHo5GNjFCRUtlU2bL2cN6jV/HcgcZ1aPA2rfVBgAjaXqvXfM7Ew== X-Google-Smtp-Source: AGHT+IFzesMsZ94IoTrpjHTjXZNdl6eAJXJB6pteF+57ev7s+DYD7H9CaPaeKuCW61gjtLGHabrG X-Received: by 2002:a05:620a:2908:b0:787:c569:edea with SMTP id m8-20020a05620a290800b00787c569edeamr7151156qkp.53.1709143474615; Wed, 28 Feb 2024 10:04:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709143474; cv=pass; d=google.com; s=arc-20160816; b=HF3OL4PbbAW4BozUmZkd1WCh1jmeqOWszikYVZCKoS3AlQ2l1z7pUpjaMlnmOBJReh MnmJnKgTDQgPxsCnv0OV+nVYRb6CnNt7nEmfrJ4afTiQhvM9UQmgan7tbQZZvlAakoqW nQOIhH/If6tacRxNxbplUL4xcmL+izgQR/FphTODUk1UbOSaqvXiTtYI0+xtSsVmpZNY 3nfBAo0oieev7RYSnKNhbzM5tIILwX4l3ylTxgr31Bsuk2q7d0jFFIKAuX8z52WVV0q/ j+0bHvE+hJvSzuGaDe6mPtY3k9BmuH7NLW8y7qcWIx+bH3fBEPh3/eart4aRom45lj+p Ft7g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:date:from:dkim-signature; bh=bBF352Tfti3FMF3gl2ozPiENjZpzK1rD95Ac73/ICZg=; fh=Lhw6W1JHk9SMm7R1uA1e2dZeUuTfsGw0484ddAl7yO4=; b=btp4D1FTKFTYwZ0uTJLW48bJjqTszAXa+iL9ffho/8GdgUEc7Flik2imlCKjU9xEr/ HaKnc6dnfQYNZsiRoR7hUYMGH327JbejMJTMfVdH+8zt4t2vRrYJu2/SdPm+buZq41I8 3X0He58LYyu6oU5VI+fIsyqBGDgY5VKgNZdmgEM7xmrEh6VIBXq1pWW8IO1w2lauiDzX To74F7F/aZ6LiSqwQgeOytUBjQxwi3HvOj5gRbU2xUeCmM8TNowefQOYnMgbuX5vO+ad e2ouItOWP2Y50GDSRBWmDfL68eBZdIYm2TVEk1yioruSZAFz8FLep0tNaV+bI0eQiy3g GAXA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ErxEuFLz; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-85500-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85500-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id s28-20020a05620a16bc00b007879b80f197si22369qkj.680.2024.02.28.10.04.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 10:04:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85500-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ErxEuFLz; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-85500-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85500-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 15FDC1C21F2B for ; Wed, 28 Feb 2024 18:04:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B93D579B81; Wed, 28 Feb 2024 18:04:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ErxEuFLz" Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.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 1E22779B6D; Wed, 28 Feb 2024 18:04:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709143467; cv=none; b=imoYCknuv4w3caI4Oc1nNIXLk55cV4ANXOiwI+4DuijE/WILbnAUqcIQK8prVGoFCz6YCVZRR1MqM85/Mdk/mpgRJO/C01Uo2Y+7LVeqXvtM/Mm7SQCph+aLJO/IMVSMnmBfNADM+TvQFXzWcMz339v6TRwH0NOK1WhVXV7ONvw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709143467; c=relaxed/simple; bh=N6U2+QaW5VeXwZH1HC6wjUMQVkEbc2qw2QuDIpP+log=; h=From:Date:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=DKnr/pt9XWbWaV7Qto0ssBfi9l7gpYHNx0I8APcX54m8jbuG8ZFMcNONatNuWcDA6BzP4wMSyg79STR/bj6nyTIzn8bUa/Uv6HzHQ4EHHLc9rFJDmhK7IfbAH5C0G7cB39uANOqYiRSyeRw+EYRDIoPXwhLW7VwtmjsO2ajVzVs= 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=ErxEuFLz; arc=none smtp.client-ip=209.85.208.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 Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-2d28464c554so57296261fa.3; Wed, 28 Feb 2024 10:04:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709143464; x=1709748264; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:from:to:cc:subject:date:message-id:reply-to; bh=bBF352Tfti3FMF3gl2ozPiENjZpzK1rD95Ac73/ICZg=; b=ErxEuFLz07eVvCknuXKL8nMbW8WuICGVzzWX1gHZp4o4RJ9/CJbVHjTaxUQ+YcPOQr 6fC61ZxJxFy6HyYrb+E8HR3Qggg161SvMwIcKBc4ugewv7Uy5gwtkGhruThNzZsQn349 q/UZHQ6FIXQTRtRRx5+TqGW2mN8YYDsr2jrgoa/cK54d+hGJRTAzP2XeE/CSYxYy+ccr YIEjj4D8GBivDnhmUv8JqN+2kdnU+D9gGWwmtXNGBocglApnEZQGVuBt3fZsUr7pjw3B VO7+oL++GnOdHfEi9cOPQyAcECl9PUvTy2ZRWEgKC6RVHrUZUx+k8fCOvQf+cJpJcy6M 7ZoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709143464; x=1709748264; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=bBF352Tfti3FMF3gl2ozPiENjZpzK1rD95Ac73/ICZg=; b=cMBT8mPcq1ZATB4/c5zAn1ka8WVPG1KsUrLaKiwY42R2O0HeqzAU0gHPuURSjxGQqN aULVyupd7zRvmfoh5UScXqcmGV8qsllMoLW21H4J/VgbArfKlkITe8h/xk+veWv44Ox9 3TShX6Pbxqel5vMXlmwhEp9rJBrsugjZHyI1p0VRISyIwuLueWhjxf656kuK1by04a+j KykIwrfTA2HCnm6hIHFpAvYYNhLOWhUmmEmf/LCqv7Vgch3dR+iL+z0CQHmkeYWvkq1s AvvwOk7vsodM+RyjlVHppt0TSREn4g1uPzBD/DeLc4k/OFs8Yu+GCJ32VdlXWYPqeCqo 5coQ== X-Forwarded-Encrypted: i=1; AJvYcCW+Ub/iFeUDJnL/n9uRj84j3E76KqRLEf6CKpVjrLUmEXQKdDtcR4r6YMU/sL61Ke9FfwQeB8enAXHR2Amn8cJ7dE8zdLFOWu1ApPNUb2cGFIqJiGKIkFsDs0wHxylmbaw2 X-Gm-Message-State: AOJu0YyqZmNmfnR8Inhn0okB3lX4AthGkYYvUG3tHqv3pqSNlJp8gR/D VSisUwOcASyLVzAsYzIFcUHhjfLwOXMWEUHj7+pAH2hn8SE2Dqz7 X-Received: by 2002:a2e:8e95:0:b0:2d2:e51f:2ba2 with SMTP id z21-20020a2e8e95000000b002d2e51f2ba2mr674576ljk.21.1709143463923; Wed, 28 Feb 2024 10:04:23 -0800 (PST) Received: from pc636 (host-90-233-206-150.mobileonline.telia.com. [90.233.206.150]) by smtp.gmail.com with ESMTPSA id a19-20020a2ebe93000000b002d283718d89sm1468562ljr.56.2024.02.28.10.04.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 10:04:23 -0800 (PST) From: Uladzislau Rezki X-Google-Original-From: Uladzislau Rezki Date: Wed, 28 Feb 2024 19:04:21 +0100 To: Frederic Weisbecker 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=us-ascii Content-Disposition: inline In-Reply-To: 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. Thanks! -- Uladzislau Rezki