From patchwork Fri Aug 11 19:48:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mateusz Guzik X-Patchwork-Id: 134676 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp1341081vqi; Fri, 11 Aug 2023 13:34:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEFuHYuRSI2MT5squJibQXGQqK6BVWgGDdjiRODywHJ2wI7jY7QLp+hcZWa/jO4nJLWIwIo X-Received: by 2002:a05:6a20:728d:b0:12f:bc36:4c67 with SMTP id o13-20020a056a20728d00b0012fbc364c67mr3806350pzk.61.1691786080924; Fri, 11 Aug 2023 13:34:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691786080; cv=none; d=google.com; s=arc-20160816; b=VgSfnW1XhFPGVRzjtaAjLxeBLyMMve+oBI2s9oUo8e62X8xAIqQ0AQwjRi6RxrnK+c u7b3foXqKLuUuwQu36KAX7H0a7TqtxR6zksJ0hw4PcTRcTL30ITBk8JhKB9BDKA3u/Vl yJ78V+dAB0RPM+7/7GsX5m0yrg9BCZn77EUdW8ZCaf4cjr+/itY+q+klEqct4qrfMAzs wuWWceNsBSZr3qo8oh4+AFGdmIlOs0J5ngi34fmKdtOSvqtvuPwNQrFz2fL8xlis3+kA WQH1Zt0js+h9qT6JonCA13AM9SOHPRYJHHOVc83rOqYqfcL2aSWkLA7Ec3R5gZBQWnQd /JWQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=v6G6ZsuSoAElNftzo3kwRe5FK/2FlGxWGqeqEHPrOvI=; fh=ro7U2rHfUQa1QrJMbNMHXoybgav6jrg8IGw1NEcWGro=; b=KqKODGVijS1+1vSjpgqxZHerZXAB0m97cjq/sd06us3Qfp8HyPG6TEqmgnsN6nzzl6 eFEs5fhH92P9XlLjjIMvIyo7Z4OWK/12+EVYmJtKAKnxc8WwiPZgsoiFb7yJzrjPEIaJ VPRwu+7a9Bd0FEz1u0mNok3Lyh+vIv1xydF80Jeeo8T/YANqykaEjjL/ffVNxXK9TxBL S+8g9CSJ7pl+uAPvnrfB5VOGMrrxcWizIoDxyWl6tHwLc3Dj+Wfpg8w45YuTNof8s2V8 cvwGzi3D3uiB//SrrHzOSEUJW0DpLKhJ9v/MI0KrLoms5gXdkTCOoCi5tyGkUBkTz48Y y98w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=RxfvhmJg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k13-20020a634b4d000000b0056476f15584si3998728pgl.541.2023.08.11.13.34.27; Fri, 11 Aug 2023 13:34:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=RxfvhmJg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236199AbjHKTs3 (ORCPT + 99 others); Fri, 11 Aug 2023 15:48:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229379AbjHKTs3 (ORCPT ); Fri, 11 Aug 2023 15:48:29 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD737EE for ; Fri, 11 Aug 2023 12:48:28 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-997c4107d62so315550366b.0 for ; Fri, 11 Aug 2023 12:48:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691783307; x=1692388107; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=v6G6ZsuSoAElNftzo3kwRe5FK/2FlGxWGqeqEHPrOvI=; b=RxfvhmJg/lkv55d73lCUiQyY749TBwr/BUK/AUEdLGM175XjeImsC36EYmC4v3vvBT bePaqmfq9kimsHXkP+U1RfnmD9bOaxMjZOu6geFDBkaVfV1gmZyB1sdzg+DOa2aFOkTV 63gzTLe1RERRAPJCMtqs/k9KdWmgP1rOcqgRGjxZCDBMgD73jWsnVSzuy98u4i6RJFrn I7KQBAg/2MT086+a/CUVhrIrwa14BZ9FpVCaF3fj2CrpDbVfbHsiOrbi23redqiCuEVX poJDRIxSkJuX8yWBUyekhFO6ThUnIkgb8aLRuPChWIva3kRkJHoug0XF3Nh8YVnxeShR vPaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691783307; x=1692388107; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=v6G6ZsuSoAElNftzo3kwRe5FK/2FlGxWGqeqEHPrOvI=; b=kMRgwwXPnAsS/vwqsNRH99J78JK5NVJ6Lm8RnlJj2CScsTvck5tPTxRr4MFoEZjPHh lgAuialiHQRY4PF3bmBkiGyOO0kS8/cO1zvYMaHoUPH6uS+wcScYQjR//YVwv1e3lpkD i/98NYnUlWIwx0QCH2S5dfevHUTv+5bqpV/IkaYFT1qZRSBUWfPK1YUiibnyQvhl+/K1 gtduAD5UI7EOzueqJvlzQ5k4IQYbgrvloa1GtJjsnQHIONbIuAuE8tKcaUj/3GvKm9Pj k+FcwGf2ShQUVbv7Rk0UHY9onKLoPozExjRhU0Dqe5IOH3di4yCy82m2dHF8EzWbDSp7 sQJw== X-Gm-Message-State: AOJu0YyFDwbLr4Gif2pJLJz3YLZHaiZWY0JNb/N7Ok0GWCC9KEKc2+q4 op5KXJ7p2e6T+idU0LVVMpU= X-Received: by 2002:a17:906:7488:b0:99c:1c8e:ac20 with SMTP id e8-20020a170906748800b0099c1c8eac20mr2423950ejl.22.1691783306898; Fri, 11 Aug 2023 12:48:26 -0700 (PDT) Received: from f.. (cst-prg-75-195.cust.vodafone.cz. [46.135.75.195]) by smtp.gmail.com with ESMTPSA id q14-20020a17090622ce00b00992ca779f42sm2598994eja.97.2023.08.11.12.48.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 12:48:26 -0700 (PDT) From: Mateusz Guzik To: brauner@kernel.org Cc: viro@zeniv.linux.org.uk, linux-kernel@vger.kernel.org, Mateusz Guzik Subject: [PATCH] vfs: fix up the assert in i_readcount_dec Date: Fri, 11 Aug 2023 21:48:14 +0200 Message-Id: <20230811194814.1612336-1-mjguzik@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773966281504392294 X-GMAIL-MSGID: 1773966281504392294 Drops a race where 2 threads could spot a positive value and both proceed to dec to -1, without reporting anything. Signed-off-by: Mateusz Guzik --- include/linux/fs.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/linux/fs.h b/include/linux/fs.h index 562f2623c9c9..21c8f8ae014d 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2613,8 +2613,7 @@ static inline bool inode_is_open_for_write(const struct inode *inode) #if defined(CONFIG_IMA) || defined(CONFIG_FILE_LOCKING) static inline void i_readcount_dec(struct inode *inode) { - BUG_ON(!atomic_read(&inode->i_readcount)); - atomic_dec(&inode->i_readcount); + BUG_ON(atomic_dec_return(&inode->i_readcount) < 0); } static inline void i_readcount_inc(struct inode *inode) {