Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp1673392rdb; Mon, 8 Jan 2024 06:56:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IFivCodC5E4c1iG2xVMIOl+8Q+ax5BTQY0gJ+nG6ImXdh0uEsR7CreVh4urUzeHZNdEX7lq X-Received: by 2002:a50:8ac4:0:b0:556:8ce1:765d with SMTP id k4-20020a508ac4000000b005568ce1765dmr2239051edk.12.1704725766618; Mon, 08 Jan 2024 06:56:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704725766; cv=none; d=google.com; s=arc-20160816; b=VuwB+V7uTRvILgPZOAJ1J8yuSYe9DKWmV8oZzECvKqY93N4utukDzo+9EWmh6kLDgn bqtm4lHhK5wl/Nxg/uX1giCN1ZLL0pqYjycuP0wi54NKNXggfCFfMpHmTH37TdJcGmET XGHH4/fkqmKhXTygQb80plduIHMb2UXCPX2tnbe9NWbKOEOkxiZp/N6UgUaLle98D1ZS Mrj15rp6Haw9SIvBLT25yYYIfQ+kzvArwsyuxEvez18V2SjPxHGCih3f+yEAycdP0peF B0CII2z7HJ/7B5jB5OUkMxFqTuJ69W5xYWe4IkCsYqhz8BECFazujzzeEMpChl7vQd2e VOyQ== ARC-Message-Signature: i=1; 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=eeXtdx992y+1nJUpXYwWG19Qi8cqqD3QCgs9gZkGRVw=; fh=0CcoJnzRo22P13o8bkCmE77tVJWX39rpUyfQTPDaoO4=; b=oNXK8wdPfong4Riwo1kcPYoCGUkzFggc9EBF3IfDMAmcTsjrsUh81sICLFxNpxmVWi s19lv1e9Wo3hj8HCXQuAaEiPsbUPJm8lNKXa0XoV9xEldOo0Q5CNW2xNw8GQ9DC4VZ/D jm0Hgn+jQ9IL1QFKlXZ+wINQhMyfC1I5Yymuo0ibUnpmzwrf8ChRfFOITAx+FQz9+Or4 wLgIZh4jHrCb5fRX6g31N+cfxikdwQ4O/IBN8utva7/fwPWmr2htyClV877fAPHxNOQ2 ME1aXPY7TNcA13QlhJeSnSWgrNUvhv42roF6N1meL22FLClvajJSRnnxpxsspP0pdeBc 7nRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@crudebyte.com header.s=kylie header.b=RJU3hCOO; spf=pass (google.com: domain of linux-kernel+bounces-19726-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19726-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=crudebyte.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id p12-20020a50cd8c000000b005575423176fsi2239175edi.508.2024.01.08.06.56.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 06:56:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-19726-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@crudebyte.com header.s=kylie header.b=RJU3hCOO; spf=pass (google.com: domain of linux-kernel+bounces-19726-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19726-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 609B61F23256 for ; Mon, 8 Jan 2024 14:56:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0112246459; Mon, 8 Jan 2024 14:56:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (4096-bit key) header.d=crudebyte.com header.i=@crudebyte.com header.b="RJU3hCOO" X-Original-To: linux-kernel@vger.kernel.org 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 DE7E745C18; Mon, 8 Jan 2024 14:55:56 +0000 (UTC) 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=eeXtdx992y+1nJUpXYwWG19Qi8cqqD3QCgs9gZkGRVw=; b=RJU3hCOOKl9TthnSWlI9/vqN1w ++SllsTqIyWLVyh3itvO5JO3Mr0EYyn0RTszfozQUgUZQ3So6QvzUozTDE0AGPGngr0b/JniJMZ80 p3W7uHj0NLHrfu+pL2PeQTN+oVHes+5pYE/LUaf8C/4vcew3jSoC4z+iZjbTjHVqLQRsq1sCzIvFR cxH07pVhBo0tYdBYIB9iroixwcRL4bp91upCQuG/SwL94rGZqAFWSJ63z7CTHCjFqTHOyTLfypb9J 8nwEe64n6URWC8+E9uXkzsCYPVRdOV09V/JUFMda5ZZ4yeBcdJzfs+639VpjSHOY9mZE/DTuHFoxA 9UJWqayb5aAgwLAoHTCOPBW1im824y4iLxk7s4wtAy5vQ1MUaTtg2bgMeA3bSD7sEuwmVcHmTCKi8 toGPuK5VEqWSAl+/BF8r7oOypYrJ6258Y77yRQUH0HZimkEo5AmNYELQa0CvlYHML5wm4kuWyTANv dt75uUlhYPkPFIoP1xeLQJRTE48iL7S/YUu5dwwVDIdKmkHBjnQl9ox3u/0mCuEiULDcD7/gJq6ZY z6q/GQIfQlOxSqSQ9NZpWiOOV/pZ1mqe8gY2kPS5QiHBc/OAo+yxcFioS0339Uju7ZHa5z/f7FrZ3 1FOHjLWC1WlOG1CbEk9BG/OUfpdtqD6qd3VUZSBrs=; From: Christian Schoenebeck To: Eric Van Hensbergen Cc: asmadeus@codewreck.org, linux-kernel@vger.kernel.org, v9fs@lists.linux.dev, rminnich@gmail.com, lucho@ionkov.net Subject: Re: [PATCH] fs/9p: fix inode nlink accounting Date: Mon, 08 Jan 2024 15:55:53 +0100 Message-ID: <7785659.j189Hiylts@silver> In-Reply-To: References: <20240107-fix-nlink-handling-v1-1-8b1f65ebc9b2@kernel.org> <8004884.rDQMAZhJ5Z@silver> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="UTF-8" On Monday, January 8, 2024 3:12:24 PM CET Eric Van Hensbergen wrote: > On Mon, Jan 8, 2024 at 6:08=E2=80=AFAM Christian Schoenebeck > wrote: > > > > On Monday, January 8, 2024 12:19:34 PM CET asmadeus@codewreck.org wrote: > > > Eric Van Hensbergen wrote on Sun, Jan 07, 2024 at 07:07:52PM +0000: > > > > I was running some regressions and noticed a (race-y) kernel warnin= g that > > > > happens when nlink becomes less than zero. Looking through the code > > > > it looks like we aren't good about protecting the inode lock when > > > > manipulating nlink and some code that was added several years ago to > > > > protect against bugs in underlying file systems nlink handling didn= 't > > > > look quite right either. I took a look at what NFS was doing and t= ried to > > > > follow similar approaches in the 9p code. > > > > > > I was about to say the set/inc/etc_nlink helpers could probably just = be > > > using atomic (there's an atomic_dec_if_postive that we could have used > > > for the v9fs_dec_count warning), but this isn't our code so not much = to > > > do about that -- I agree it needs a lock. > > > > > > I didn't take the time to check if you missed any, but it won't be wo= rse > > > than what we have right now: > > > Acked-by: Dominique Martinet > > > > That's actually a good point. For these tasks atomic inc/sub/etc are us= ually > > used instead of locks. > > > > I would at least add local wrapper functions that would do these spinlo= cks for > > us. > > >=20 > I'm good with adding local wrapper functions, I imagine these aren't > used in the kernel because for regular file-systems maybe you want the > warning that your inode link accounting is wrong. > I suppose we could be naughty and not use the kernel functions (which > themselves are basically wrappers). Well, one half of that code is actually using atomic operations to incremen= t/ decrement the private counter. Which means to me those kernel functions were intended to be called from a concurrent context. So I don't get why the oth= er variable is not atomic there. They should be I think. I would probably try and send a patch for changing those kernel functions a= nd see if people are fine with that. But up to you.