Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5326075rdb; Wed, 13 Dec 2023 05:51:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IHoASpa59Zc67mTkZNjxCAYiFshkGA2kiHEFh1rrFUfXdyjaY3aMaMQbRVSkGIkv/n8H0ge X-Received: by 2002:a05:6a20:3d0d:b0:18c:26cc:c054 with SMTP id y13-20020a056a203d0d00b0018c26ccc054mr10226636pzi.7.1702475478527; Wed, 13 Dec 2023 05:51:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702475478; cv=none; d=google.com; s=arc-20160816; b=Rhd3jJQNa4JYmUExIMj9lqK/mB2V76ZM9RmcpIWMb5/HSo4Yggvem0MW7u/tE2xggE XFQei3MpAlMRZ9aadrUDl+uljy0fTOo9qx7qrG4qjD1IPf7qEYLY+0NynPKED5OJuVRo KBV+FiEyvlmmJGF2bidPq92YEoMrDRNOOx6Z4G98ckF2mBa8+S9lOE1cX0xGh2FETL12 +GL7B2NtpG5BOdxL9uNbgp2p4AJlRXVRWo+ofmioouaRjXfebZ61D2/4gB6fQ6i+8+Q2 EvwCQcLfcmri4cUm3T3ooYtDljWtzIAzzrLteXf6F6B08KQT6p0siorbW9XRnTdzMSA+ bSFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=i4ME/XIpRFu9lqWi6l0Lhi5Qaw7MTTiMqknldjpYnCU=; fh=9eDgTo8aIuwg9MpGeudPwJT3CA93x8I1cKC8E1Wz3RU=; b=rpdwOs7a6+XLgzjIBetozkDK0Gms0HxJodDlkf5yrE5QNKLkZueODvVLFySV0XsjrA ZLhnuE+JxSUYhbMDkz4jUe32+zhihahB4eKhRzHBQerQQ6XC3T4OFvnccjhzBCYx7dlf 89mYaYY4XZwR0AKC+MyUvAJV4aVH7/DvB42QGZjyE6esv05eQ718D1J5tFWNqeQaICuz g5QSBvWuPwvKOP9QIsbMQPUNeg4tL6n47MA02FZbV53SPF3XQ4ysLsjU6hmGwWodanSX 1I1kxektUS4iFO6LN5Z/iZWj7qPxEhDm+LdGn+ak7YaiBYJUlv+YcC8LhJF9Q8uYt9Vw lfgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cTWboUxL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id 36-20020a631564000000b005c625af78acsi9563016pgv.881.2023.12.13.05.51.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 05:51:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cTWboUxL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 0DDE880B9F81; Wed, 13 Dec 2023 05:50:37 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379052AbjLMNuH (ORCPT + 99 others); Wed, 13 Dec 2023 08:50:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378960AbjLMNuG (ORCPT ); Wed, 13 Dec 2023 08:50:06 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7C4A9C for ; Wed, 13 Dec 2023 05:50:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475412; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i4ME/XIpRFu9lqWi6l0Lhi5Qaw7MTTiMqknldjpYnCU=; b=cTWboUxL7kK5Hp1oFYGEdSqXcuNXQJsIfasMcEQZ0Sfpx3J4b7ncZ1f/PluD7B9n3W1ywI b7eeIeSuQGoXCH/GTgjczY3liDPDMM5BXVH6wKTPII180HdepwnMFxHx22OycFCbiJNd3N 3wt3u5ikb3bJFcGsgFMSYQZqSaxeMbg= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-636-SYx12FEyMpiqyNK_cS8-rQ-1; Wed, 13 Dec 2023 08:50:08 -0500 X-MC-Unique: SYx12FEyMpiqyNK_cS8-rQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7997185A597; Wed, 13 Dec 2023 13:50:08 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 82A58C1596E; Wed, 13 Dec 2023 13:50:07 +0000 (UTC) From: David Howells To: Marc Dionne Cc: David Howells , linux-afs@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Oleg Nesterov Subject: [PATCH v2 01/40] afs: fix the usage of read_seqbegin_or_lock() in afs_lookup_volume_rcu() Date: Wed, 13 Dec 2023 13:49:23 +0000 Message-ID: <20231213135003.367397-2-dhowells@redhat.com> In-Reply-To: <20231213135003.367397-1-dhowells@redhat.com> References: <20231213135003.367397-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 13 Dec 2023 05:50:37 -0800 (PST) From: Oleg Nesterov David Howells says: (2) afs_lookup_volume_rcu(). There can be a lot of volumes known by a system. A thousand would require a 10-step walk and this is drivable by remote operation, so I think this should probably take a lock on the second pass too. Make the "seq" counter odd on the 2nd pass, otherwise read_seqbegin_or_lock() never takes the lock. Signed-off-by: Oleg Nesterov Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org Link: https://lore.kernel.org/r/20231130115606.GA21571@redhat.com/ --- fs/afs/callback.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/afs/callback.c b/fs/afs/callback.c index a484fa642808..90f9b2a46ff4 100644 --- a/fs/afs/callback.c +++ b/fs/afs/callback.c @@ -110,13 +110,14 @@ static struct afs_volume *afs_lookup_volume_rcu(struct afs_cell *cell, { struct afs_volume *volume = NULL; struct rb_node *p; - int seq = 0; + int seq = 1; do { /* Unfortunately, rbtree walking doesn't give reliable results * under just the RCU read lock, so we have to check for * changes. */ + seq++; /* 2 on the 1st/lockless path, otherwise odd */ read_seqbegin_or_lock(&cell->volume_lock, &seq); p = rcu_dereference_raw(cell->volumes.rb_node);