Received: by 2002:ab2:7855:0:b0:1f9:5764:f03e with SMTP id m21csp886858lqp; Thu, 23 May 2024 03:06:15 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXFzbJaae7Paw+cGWAnyfvb2rO6FE00y4+kfB/Mnkga2KaxGryrqmOEDsXwYVHuhGYwH/K9e50gOVNcsPvVwCk2mn46ohqqStKUiDsaPg== X-Google-Smtp-Source: AGHT+IGJT1XF5jzicMmU/ZiqnQ5o0QAs2DhciUHUwelTH7+V9ubJNV3m9adsj156pTfM91CnuPxm X-Received: by 2002:a05:6870:d0c4:b0:23a:2ddc:30d4 with SMTP id 586e51a60fabf-24c68a8e356mr5013763fac.23.1716458774944; Thu, 23 May 2024 03:06:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716458774; cv=pass; d=google.com; s=arc-20160816; b=a9jEhKKNXLGkrdTRSvEed/0M0EXl8Jj+m/7Uh1KdVhdlpqj4vChfozIUwSTPSYOJqn jJpHpo95hSztJQCj3D0gmevERtCYlkIWQ8lkd8YDuPmLClDq+m1YEC9I3PSWEQt3SfNp FtcBQWrVVJLf2pkhcfyieAj+CEn4qqyhN+a/RC3tQAs2gczNjnEYnT+hFFdD28ujTNWg eI3MSHp1BUfdfz9Cv5goGYBzUytofhhJdNnf7DBlj9VMVLxBwoFGo73JNvEcSoTqF3SZ OR1WQRbhjjYCGFsqRTOuj8H5Hxh0+FX2Os2BUmELyPo8tL6yQ6dRmOAopJ401sJ0Mw7U isgQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=f8jC17nCt232w/3lqbKjfEROHlbH51l5S8kUPNZoSNw=; fh=jH0GsDty/7liQsDWMC+4I5popBrDJ99oWJfzuQ6lTyc=; b=bdJffDx5PSlFsJS5FOV3T25DGB0371RQmCRvJcgA3F9LhZJF+LPYc4Qf8w6MAApNxU 5lMEE/rySJEqYUuUikhU6Top1ZW/MrrkRPqa/PdjnTxe9RdPFLzXzkzfAzp6glrcw/31 4u4WmGbfXXEYsyFTfI8B98Ng8zaZp53bmbzHwAgc6MLYkUM8ZmSVCykgujNNXYmP8ofA NWXKBHVl4Rl7NjAFzI9XoxCuWnUsu57GnESCCzDNdB9g7GtkA5PfYq8iGLhp3KErfPBJ olgbtKHztMN7livF/l2/WI3gnMnZIB6liHDZ3bkgdYYQks5s60Utwi+RhPxm29uSmsBJ hhgg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@crudebyte.com header.s=kylie header.b=o8PXcoLF; arc=pass (i=1 spf=pass spfdomain=crudebyte.com dkim=pass dkdomain=crudebyte.com dmarc=pass fromdomain=crudebyte.com); spf=pass (google.com: domain of linux-kernel+bounces-187306-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187306-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=crudebyte.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d2e1a72fcca58-6f4d2b2feebsi1151768b3a.298.2024.05.23.03.06.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 03:06:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-187306-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=@crudebyte.com header.s=kylie header.b=o8PXcoLF; arc=pass (i=1 spf=pass spfdomain=crudebyte.com dkim=pass dkdomain=crudebyte.com dmarc=pass fromdomain=crudebyte.com); spf=pass (google.com: domain of linux-kernel+bounces-187306-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187306-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=crudebyte.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 8BA33281887 for ; Thu, 23 May 2024 10:06:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5530213DDB8; Thu, 23 May 2024 10:06:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (4096-bit key) header.d=crudebyte.com header.i=@crudebyte.com header.b="o8PXcoLF" Received: from kylie.crudebyte.com (kylie.crudebyte.com [5.189.157.229]) (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 3F58654FA9; Thu, 23 May 2024 10:06:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=5.189.157.229 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716458767; cv=none; b=lREXmyNzv/CJa378ZnBy3C1KPx414oy8V5BoG3oV9fX4dkWFiiWjCN46T2XP/rlFhkkivF7L5+qrOrQUD+cqlRbyKF3S3qxlaAw4GaApq4chLHC+Hn2rvF1WVOQUeD5VlvslFqGFEz3BqkhXxQNOC8Z4K0DjrnE6TjH2WP/Q7RA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716458767; c=relaxed/simple; bh=6hZfU/vZlrz4/bVBw0R53ZF51GPkuNffAAaPgUYgJMM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dett5vARAR1lZPlSHBh8o9e60PRY+b2CKJr8DNhuk9/sUhwSgmlTfMf/j8D0HvaHK5avA0IGskPclNQlcIdP3a0IVove6yImYBb9qeP8ZPkStiBf/r2FiFHbxVikTrDBUAl9HMAIBRgNaEq5dqwcLsWMR5X74G1+exQFffwfJ1s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=crudebyte.com; spf=pass smtp.mailfrom=crudebyte.com; dkim=pass (4096-bit key) header.d=crudebyte.com header.i=@crudebyte.com header.b=o8PXcoLF; arc=none smtp.client-ip=5.189.157.229 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=crudebyte.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=crudebyte.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=kylie; h=Content-Type:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Content-ID:Content-Description; bh=f8jC17nCt232w/3lqbKjfEROHlbH51l5S8kUPNZoSNw=; b=o8PXcoLFtZFkuMCBmDWq+qpc+k Z1muJ0pfMgOzZJ6+41nkyh0+fyRmX27rfctbCLX4Pe2SH7oVYsR6RUifgKykHr3prBkVOD8cVKWae jOsAbsLdpKwjbHD/LCCk9eoVOF9avnwEk/9FyPaRfIVZEj+q1qjimPCJio7KYuCt4GcKCw0DIjOk5 Gf7sKHCppxAE+qQJ3ETeBcr4m+9v+klRmLiSOiNswLvzVjISMCnW+GDLRJATaHLp4QEB9KxLnkVGy MLMgq+2YzSsBMMNJ7ipirr+zYb/5haXrY5XUO08JWTH40ldZJTsDrZU9JvbF1wjrynDQWNnrHQsvY 2gXfa7Z+xV6INwNd8bjats2GjC+ZCXKMBN4TWir1r9fkgEgfeaODFRmPe4wsjDdVR5/Kcw39zwjLn ytAUyuVRlmJZsEi36i8/kNm1Po9NQHo8yqGu4I6BSRSdau9eYkQh5Z6dPxkanT8bf1XhFO16yW+WA Q1FcCWKz9WL8p7DJm+sQeKHCjlT6dkw3B76soDP8JbrKP9o5xTBthhEIm2EtbCLBaxSf3O3YwDcPt foSkcm9qYyOWwpeR+NAVjBfeMaTlD3n2SeUCQRLLKjdFxnhA0Fz8tHYq3OzVEvaEMjnExWGjwzPhz u2+lq7c0KNPraDlCrd8qwBZw68g/RqLL6AeKfI+qs=; From: Christian Schoenebeck To: Dominique Martinet Cc: Eric Van Hensbergen , Latchesar Ionkov , Greg Kurz , Jianyong Wu , stable@vger.kernel.org, Eric Van Hensbergen , v9fs@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH] 9p: add missing locking around taking dentry fid list Date: Thu, 23 May 2024 12:05:44 +0200 Message-ID: <2675095.dNBKFZOyUv@silver> In-Reply-To: References: <20240521122947.1080227-1-asmadeus@codewreck.org> <3116644.1xDzT5uuKM@silver> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" On Thursday, May 23, 2024 11:27:28 AM CEST Dominique Martinet wrote: > Christian Schoenebeck wrote on Thu, May 23, 2024 at 10:34:14AM +0200: > > > The comment still works -- if detry->d_fsdata is NULL then > > > hlist_for_each_entry will stop short and not iterate over anything (it > > > won't bug out), so that part is fine in my opinion. > > > > I meant the opposite: dentry->d_fsdata not being NULL. > > I also meant that in the d_fsdata not being NULL branch, if d_fsdata > turns out to be NULL when it is read under lock later. > > > In this case v9fs_fid_find() takes a local copy of the list head > > pointer as `h` without taking a lock before. > > It doesn't, it takes &dentry->d_fsdata so the address of d_fsdata before > the lock, but that address cannot change here (another thread cannot > change the address of the dentry) ...(continuing below) Aaah right, I was missing the `&`, my bad! > > Then v9fs_fid_find() takes the lock to run hlist_for_each_entry(), but at this > > point `h` could already point at garbage. > > ... so *h (in practice, head->first in hlist_for_each_entry()) will > properly contain the first node of the list under lock: either NULL if > we just cleared it (at which point the loop won't iterate anything), or > a new list if other items have been added meanwhile. Yeah, looks fine to me. > I really think it's safe, but I do agree that it's hard to read, happy > to move the `h = &dentry->d_fsdata` inside the lock if you prefer -- it > compiles to the same code for me (x86_64/gcc 13.2.0) No need, you can add my RB. Thanks for the clarification! Reviewed-by: Christian Schoenebeck