From patchwork Mon Mar 4 16:35:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 209401 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp1269535dyc; Sun, 3 Mar 2024 23:40:03 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVO17+06IVwz/28NmIBAD1UMK1vRA20o4GY4JBwVjJb+6NPrb6Scb1B+YnawCNp8Zqu6bA/FNxPQJqadqS16L9DlfRZMg== X-Google-Smtp-Source: AGHT+IHhshFk/r5cgmLC7fdhacF5UhqiHNMN0mkQJ4RNwHMqZIBLyx9U1x32eDaYKJziBdM/Y40h X-Received: by 2002:a17:907:1004:b0:a44:277c:1684 with SMTP id ox4-20020a170907100400b00a44277c1684mr5120034ejb.47.1709538003316; Sun, 03 Mar 2024 23:40:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709538003; cv=pass; d=google.com; s=arc-20160816; b=t5A6czKjDMJLoT8IrK7cW6Xl+Gdoke8aoHixbYj8btAULkRKT1wiEfHkNsx+6ipE6M +juwNFI13vxQNyVOCyBfV+LxH8Pvo+4bZQZTWeokAxXc8oRj/me8cJgpOpM0aGn4CxNk NuKumQjymUs5csq2KP+7A7pJjLdojsxSAKWVgIsukf1VjDarQREMYbeK9ZFfM/NYj+jA LwaXJ0lzhOEozbseN0RC57RLf1HThRnUeNI2qB9rLe6b1q1NxagZlO5E0uozYOAIagxB rx++PdG1T0hYnOKRmTHAnpOYGg7x/olHa7rB51Fmgy+m+juAeKrWL9OGbhtxyDuWtqdW DTwg== 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; bh=egNS0bTvMdjFpZkE9ib0dR26MBlF/wBsHdF+zXIhYTc=; fh=F5xKjzVfoX4U1ctxq5p9Tuw3OchS51SLNsBn6NIWrhw=; b=alFNoFqp7t+24eWqEZgz8NRrAMib1VBr3bYEeEr5wLRGow2bBzyjzlCKt0l+0dI4x+ Xk0CrO+sjz+oTO0AHcJYbzue1jMhs3gUopKpkzvkl4vRYETJuAkOHGQMnsFHSqf8KBA3 OTXIdAWYZN6m+EJHaOuTSilhYjgud89srwf6tRgzg8VyL007Y0QAd4zN9vQJ9myPfrWR ztnLjfv6TYKCD/J2W8t7NP87UeJtZXL0/KN29r4f603eYVbeQUUENzJH8DdUwo7IQNVR D6uac4K2Ri3F5HfDuiQXru3oO5yxQilk2acOicpRYshanoKPayIwjSZ/HnjkjgeaFEqf MDhg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-90144-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90144-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id lt27-20020a170906fa9b00b00a457b858e1dsi43224ejb.1016.2024.03.03.23.40.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Mar 2024 23:40:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-90144-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-90144-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90144-ouuuleilei=gmail.com@vger.kernel.org" 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 C2E2B1F228CA for ; Mon, 4 Mar 2024 07:40:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9524D179BF; Mon, 4 Mar 2024 07:39:14 +0000 (UTC) Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (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 ACDDA13FFD; Mon, 4 Mar 2024 07:39:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709537952; cv=none; b=j53Wl5Vr7UP3tfZOhcycPr5n0cr3wJAQTAbm3YugLZ679zH9BFT4Mgsrt8nnofTyuIa814JZNyfpfNd1Z5JhYa670F2AFNSNZ2PekEdhB+Llw71N6mmB2nK8xFKZ94sN1tPk8kcwHrOHsX9qttHwDZFGtin9Sot2aMf+q569b7U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709537952; c=relaxed/simple; bh=/LhgKrGSOiaYrC11cugO+xFYJU1yWEdd+eAWZriHGQQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=YjUhijaR+7UAFf9AF4QUeTHCH8bNJsLCWPY6McwC5uS6H1zyhUnSwHnJ/2zw6bfStPYgTaLc4Jo3qAPE8iOk5JyOBnW+G/QBnx9XdMY5tcgzluFrmJaPOaFBshQGX49G7R8EF5HjeuBwDzjhNSTjagj7wDdHCk0uAMsr2itXlWA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Tp9Yb6VSzz4f3mHK; Mon, 4 Mar 2024 15:38:59 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 5C8DF1A04BC; Mon, 4 Mar 2024 15:39:07 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.101.6]) by APP4 (Coremail) with SMTP id gCh0CgDXKGuXeuVlWUH1Fw--.2277S3; Mon, 04 Mar 2024 15:39:07 +0800 (CST) From: Kemeng Shi To: tytso@mit.edu, adilger.kernel@dilger.ca Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, naresh.kamboju@linaro.org, daniel.diaz@linaro.org, linux@roeck-us.net, brauner@kernel.org Subject: [PATCH v4 1/3] ext4: alloc test super block from sget Date: Tue, 5 Mar 2024 00:35:41 +0800 Message-Id: <20240304163543.6700-2-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20240304163543.6700-1-shikemeng@huaweicloud.com> References: <20240304163543.6700-1-shikemeng@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: gCh0CgDXKGuXeuVlWUH1Fw--.2277S3 X-Coremail-Antispam: 1UD129KBjvJXoWxGF1rGw1DCr18uw1fJF47Jwb_yoWrWFyrpa 43AFyFkr48uF4q9an7JFykXr1S9a109ryDGrWI9w15JayYgry8GFWvyF1jyrWFqrWxGFZ3 ZF1UKrWUCr4UGa7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUB0b4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M280x2IEY4vEnII2IxkI6r1a6r45M2 8IrcIa0xkI8VA2jI8067AKxVWUGwA2048vs2IY020Ec7CjxVAFwI0_JFI_Gr1l8cAvFVAK 0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4 x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l 84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I 8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AK xVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64 vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8G jcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2I x0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK 8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I 0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUsWrWDUUUU X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792580521133325711 X-GMAIL-MSGID: 1792580521133325711 This fix the oops in ext4 unit test which is cuased by NULL sb.s_user_ns as following: <4>[ 14.344565] map_id_range_down (kernel/user_namespace.c:318) <4>[ 14.345378] make_kuid (kernel/user_namespace.c:415) <4>[ 14.345998] inode_init_always (include/linux/fs.h:1375 fs/inode.c:174) <4>[ 14.346696] alloc_inode (fs/inode.c:268) <4>[ 14.347353] new_inode_pseudo (fs/inode.c:1007) <4>[ 14.348016] new_inode (fs/inode.c:1033) <4>[ 14.348644] ext4_mb_init (fs/ext4/mballoc.c:3404 fs/ext4/mballoc.c:3719) <4>[ 14.349312] mbt_kunit_init (fs/ext4/mballoc-test.c:57 fs/ext4/mballoc-test.c:314) <4>[ 14.349983] kunit_try_run_case (lib/kunit/test.c:388 lib/kunit/test.c:443) <4>[ 14.350696] kunit_generic_run_threadfn_adapter (lib/kunit/try-catch.c:30) <4>[ 14.351530] kthread (kernel/kthread.c:388) <4>[ 14.352168] ret_from_fork (arch/arm64/kernel/entry.S:861) <0>[ 14.353385] Code: 52808004 b8236ae7 72be5e44 b90004c4 (38e368a1) Alloc test super block from sget to properly initialize test super block to fix the issue. Signed-off-by: Kemeng Shi Reported-by: Linux Kernel Functional Testing Reported-by: Guenter Roeck --- fs/ext4/mballoc-test.c | 55 ++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/fs/ext4/mballoc-test.c b/fs/ext4/mballoc-test.c index 12d0b22cabe1..9d061f80f150 100644 --- a/fs/ext4/mballoc-test.c +++ b/fs/ext4/mballoc-test.c @@ -21,16 +21,28 @@ struct mbt_ctx { }; struct mbt_ext4_super_block { - struct super_block sb; + struct ext4_super_block es; + struct ext4_sb_info sbi; struct mbt_ctx mbt_ctx; }; -#define MBT_CTX(_sb) (&(container_of((_sb), struct mbt_ext4_super_block, sb)->mbt_ctx)) +#define MBT_SB(_sb) (container_of((_sb)->s_fs_info, struct mbt_ext4_super_block, sbi)) +#define MBT_CTX(_sb) (&MBT_SB(_sb)->mbt_ctx) #define MBT_GRP_CTX(_sb, _group) (&MBT_CTX(_sb)->grp_ctx[_group]) static const struct super_operations mbt_sops = { }; +static void mbt_kill_sb(struct super_block *sb) +{ + generic_shutdown_super(sb); +} + +static struct file_system_type mbt_fs_type = { + .name = "mballoc test", + .kill_sb = mbt_kill_sb, +}; + static int mbt_mb_init(struct super_block *sb) { int ret; @@ -72,43 +84,54 @@ static void mbt_mb_release(struct super_block *sb) kfree(sb->s_bdev); } +static int mbt_set(struct super_block *sb, void *data) +{ + return 0; +} + static struct super_block *mbt_ext4_alloc_super_block(void) { - struct ext4_super_block *es = kzalloc(sizeof(*es), GFP_KERNEL); - struct ext4_sb_info *sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); - struct mbt_ext4_super_block *fsb = kzalloc(sizeof(*fsb), GFP_KERNEL); + struct mbt_ext4_super_block *fsb; + struct super_block *sb; + struct ext4_sb_info *sbi; - if (fsb == NULL || sbi == NULL || es == NULL) + fsb = kzalloc(sizeof(*fsb), GFP_KERNEL); + if (fsb == NULL) + return NULL; + + sb = sget(&mbt_fs_type, NULL, mbt_set, 0, NULL); + if (IS_ERR(sb)) goto out; + sbi = &fsb->sbi; + sbi->s_blockgroup_lock = kzalloc(sizeof(struct blockgroup_lock), GFP_KERNEL); if (!sbi->s_blockgroup_lock) - goto out; + goto out_deactivate; bgl_lock_init(sbi->s_blockgroup_lock); - sbi->s_es = es; - fsb->sb.s_fs_info = sbi; + sbi->s_es = &fsb->es; + sb->s_fs_info = sbi; - return &fsb->sb; + up_write(&sb->s_umount); + return sb; +out_deactivate: + deactivate_locked_super(sb); out: kfree(fsb); - kfree(sbi); - kfree(es); return NULL; } static void mbt_ext4_free_super_block(struct super_block *sb) { - struct mbt_ext4_super_block *fsb = - container_of(sb, struct mbt_ext4_super_block, sb); + struct mbt_ext4_super_block *fsb = MBT_SB(sb); struct ext4_sb_info *sbi = EXT4_SB(sb); kfree(sbi->s_blockgroup_lock); - kfree(sbi->s_es); - kfree(sbi); + deactivate_super(sb); kfree(fsb); } From patchwork Mon Mar 4 16:35:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 209400 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp1269493dyc; Sun, 3 Mar 2024 23:39:53 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXXXECFhNUrQepKoArQ3UWKUsN3VlN1IJGlsg/2/+1t++YBVGq1vSMSLc4EU3gC1saXTEtnJXURkoAPTd0JcyfvgjiNeA== X-Google-Smtp-Source: AGHT+IGcmrOex5LE7pYn1qyx/DwZv4vtVvWfAgap6xLf8DXCjL2kjCuAUCTs+NblgvjQsmefao3e X-Received: by 2002:a05:620a:120a:b0:788:2631:187b with SMTP id u10-20020a05620a120a00b007882631187bmr3016378qkj.32.1709537993395; Sun, 03 Mar 2024 23:39:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709537993; cv=pass; d=google.com; s=arc-20160816; b=RVvCvqlshrNyGcuzPbX6H8px1AVyrxeK/AY7eSPkoWhQkqOrtPZ8Bqu28tmBUZ1GTc 8dS+K+km5kLjsiYMn8gwwMOWJ77PqFnXKRvmc6jIEPFh22cy7U99ubBvmxnq4kFQRt43 XpzfnZLZJrvJCcyrk5iDCgJTKQSvancL7fwqd0CAWD3Ck/kC734TAIWbZooqTmVXkh7v G4k4RCLJfpp7yfdOUWW/IwEU2fQpYWGK6yj1E7LoeHi6YJf/wPUEqMxFouYOXnmKWocr suO2C0fb3e88S1QYpkrT/hEJ9roVHvMrs0sITr+hXDIKbF0SPTYofLQS/ZbWtRXKi/XB EazA== 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; bh=kmb37C75iFQyVFimvHqSV6Yb2YsB5ijhZiCHbS+aA7k=; fh=F5xKjzVfoX4U1ctxq5p9Tuw3OchS51SLNsBn6NIWrhw=; b=NMs2kNfuSXxjEPDldpPdY8Rb5/KSM3Bczc0D6otU3CbA7HeFMvB7omZ1D+BAIRUzsw rpEyIK2ushY/FTK9uny1d+m5T+llwq/ygcFXtBrLyfs7vakTh+48AHiwj3lq1o27oeTP Dpa7pq9b8WIVW0rfdJJ88dI7wXubSTgE0LR9mz4E7w9ZXwRYpUhMDwG7e9Y4ggAszt3z Z4rwePwP1RDVhk+RNXJ2db4LXb7fLsL0V86lIW1YRtY6IL6T3Z5u5ICHOoQqnEEzKqfU iWOl8kGg09h5Ks1jL+ewuXmp+iiBt/ixWfTHcqavhQkocX/0ElFGmoSn9Pysn1g+IiUP 6atw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-90145-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90145-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id vr9-20020a05620a55a900b007882e4c9ce3si353793qkn.122.2024.03.03.23.39.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Mar 2024 23:39:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-90145-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-90145-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90145-ouuuleilei=gmail.com@vger.kernel.org" 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 320521C213A4 for ; Mon, 4 Mar 2024 07:39:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4DACE175AE; Mon, 4 Mar 2024 07:39:14 +0000 (UTC) Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (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 ACE2014ABA; Mon, 4 Mar 2024 07:39:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709537952; cv=none; b=a0J+/oNDzCHxj47jugzJ73CBvNJJZC4NYAMBb0G2Kj0tBD/xejBLI4/cChrgM3kfhNrN91dY5UmGg+oLFwCvGDBL/Nj+vIN/xWqSb1mlJ81GCjiLiVBC3A/fpljy0IwD3OJwYlSDikjz4zwVxQghNDkjO2EJ6reuZcAys9Ih0Bg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709537952; c=relaxed/simple; bh=5hzRnUh34nUYKLiZt7NaTdrTOrhwlApFtHI+0BahY4k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fmMVoRjzZJZtPfNsNSl6Px/WfVXnFXeIin+NnJBAwXRLga+IcYQM3ko3A00h2Ud6F1B4vtyK95BWoUHbhNTuCKVr4OPk8gXWemHn4JRR2OMg6pol4c4IsX3XpbTUQalcG1U9fJ9bkgdmWGH8ESe8sXeyJDeTBlOiPOhN2EDfHJk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Tp9Yh1z9lz4f3jHV; Mon, 4 Mar 2024 15:39:04 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id B7B371A0172; Mon, 4 Mar 2024 15:39:07 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.101.6]) by APP4 (Coremail) with SMTP id gCh0CgDXKGuXeuVlWUH1Fw--.2277S4; Mon, 04 Mar 2024 15:39:07 +0800 (CST) From: Kemeng Shi To: tytso@mit.edu, adilger.kernel@dilger.ca Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, naresh.kamboju@linaro.org, daniel.diaz@linaro.org, linux@roeck-us.net, brauner@kernel.org Subject: [PATCH v4 2/3] ext4: hold group lock in ext4 kunit test Date: Tue, 5 Mar 2024 00:35:42 +0800 Message-Id: <20240304163543.6700-3-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20240304163543.6700-1-shikemeng@huaweicloud.com> References: <20240304163543.6700-1-shikemeng@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: gCh0CgDXKGuXeuVlWUH1Fw--.2277S4 X-Coremail-Antispam: 1UD129KBjvJXoW7tw1UuFyUArWrur17KFyUJrb_yoW8ArW8pa nxCrn0kF45Wr1kuw47G3y0q3Z7Kw4kuw18GrWfCw1fArWfJr9rCF98twnIgr48tF4xXF45 A3Z0vry3Crs7uaUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUB0b4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M280x2IEY4vEnII2IxkI6r1a6r45M2 8IrcIa0xkI8VA2jI8067AKxVWUXwA2048vs2IY020Ec7CjxVAFwI0_Gr0_Xr1l8cAvFVAK 0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4 x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l 84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I 8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AK xVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64 vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8G jcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2I x0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK 8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I 0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxU3lApDUUUU X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792580510829100940 X-GMAIL-MSGID: 1792580510829100940 Although there is no concurrent block allocation/free in unit test, internal functions mb_mark_used and mb_free_blocks assert group lock is always held. Acquire group before calling mb_mark_used and mb_free_blocks in unit test to avoid the assertion. Signed-off-by: Kemeng Shi Reported-by: Guenter Roeck --- fs/ext4/mballoc-test.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/ext4/mballoc-test.c b/fs/ext4/mballoc-test.c index 9d061f80f150..4d9eb4807c98 100644 --- a/fs/ext4/mballoc-test.c +++ b/fs/ext4/mballoc-test.c @@ -701,7 +701,10 @@ test_mb_mark_used_range(struct kunit *test, struct ext4_buddy *e4b, ex.fe_start = start; ex.fe_len = len; ex.fe_group = TEST_GOAL_GROUP; + + ext4_lock_group(sb, TEST_GOAL_GROUP); mb_mark_used(e4b, &ex); + ext4_unlock_group(sb, TEST_GOAL_GROUP); mb_set_bits(bitmap, start, len); /* bypass bb_free validatoin in ext4_mb_generate_buddy */ @@ -761,7 +764,9 @@ test_mb_free_blocks_range(struct kunit *test, struct ext4_buddy *e4b, if (len == 0) return; + ext4_lock_group(sb, e4b->bd_group); mb_free_blocks(NULL, e4b, start, len); + ext4_unlock_group(sb, e4b->bd_group); mb_clear_bits(bitmap, start, len); /* bypass bb_free validatoin in ext4_mb_generate_buddy */ @@ -805,7 +810,11 @@ static void test_mb_free_blocks(struct kunit *test) ex.fe_start = 0; ex.fe_len = EXT4_CLUSTERS_PER_GROUP(sb); ex.fe_group = TEST_GOAL_GROUP; + + ext4_lock_group(sb, TEST_GOAL_GROUP); mb_mark_used(&e4b, &ex); + ext4_unlock_group(sb, TEST_GOAL_GROUP); + grp->bb_free = 0; memset(bitmap, 0xff, sb->s_blocksize); From patchwork Mon Mar 4 16:35:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kemeng Shi X-Patchwork-Id: 209402 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:fa17:b0:10a:f01:a869 with SMTP id ju23csp1270569dyc; Sun, 3 Mar 2024 23:43:24 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWdPCFwciLZQ4YwJkmxLbrenaX1dneIfkymOBtUWoEaaoF5qS8lzIKNhFmErJmk3hs0juZiXAwC86TfwACUgyjVtSauQg== X-Google-Smtp-Source: AGHT+IHC48/m/PUOp6mjjkXyZ0Sc0JdEZFkA8tVhmQ/Qzlo8jsSCo0O3gL0s7F63+4+dNkRpEqnY X-Received: by 2002:a05:6808:4197:b0:3c1:f4bb:1f15 with SMTP id dj23-20020a056808419700b003c1f4bb1f15mr278810oib.23.1709538204511; Sun, 03 Mar 2024 23:43:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709538204; cv=pass; d=google.com; s=arc-20160816; b=VhFKG0Nxr77CalQsl2aqVLi6yo4sykhwuQHCcsxhin0tR9/kyupnL0WSayRdmTfHYH q4PSL9Pk6mWkcp8LSvRh3IsgfNUURiNlfaTJJplKdHDS6QWI7URco70QXsZYTBVFpY3F njcG26dQfamI3eQ0jdveRyJmvgwVon3gYD/pI8/3Zv+uMzN1kaxqf6ldcHp64Ve40rfa YC9iNZs/sbMvjmnKd9hodEaVt1lvkXzYXbMvRFtByt9h9K7iiZwlbzslKN/VPCG1+aDa leTXIMyHi9iuqbG5wiI1jzHw/ptJdfWRepAeDC4GqgAZwvNT3aVEqK5XP4DLun1gP+u+ eocg== 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; bh=OBanf7wes28qmQWLaVCw4UnyVNmG8BZwKvt8I0FDFPU=; fh=F5xKjzVfoX4U1ctxq5p9Tuw3OchS51SLNsBn6NIWrhw=; b=dkfhac4r3UaLtWmWtVvdlmgdeDY6S7t6/WltIeqS7M0Z5c0SlETCmvWcz+U8KIDY4D /dfxpkbZ9Urb/1QYN2fq3l4KCnJ9zzKjYk7sa5g+ckFfKnjIszj/FYpzJfowSqgudKQL S1X22VzuZcdzZ/UM1wBV266Lx4IX4gGuNkpzGHFIeP6FkKQ7nA5X/nujRtrkb238tnUT 7kmJOcUjPWARex6NirB+etuwR7JV6WyBUNqitq8W0HWClxlLOW6Mc5yvvSpRiUe3NNNP QDgvuQMh9aX8FSVTLsxCAU8Ykx7gwnWLwjFaYnyLotK4fMjbOW4mv81MXTaBjkuvbHWz b78w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-90147-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90147-ouuuleilei=gmail.com@vger.kernel.org" Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 19-20020a631753000000b005cdf9c9b7e3si7882292pgx.179.2024.03.03.23.43.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Mar 2024 23:43:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-90147-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-90147-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90147-ouuuleilei=gmail.com@vger.kernel.org" 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id C7CB5B21821 for ; Mon, 4 Mar 2024 07:40:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5CAF417C6C; Mon, 4 Mar 2024 07:39:15 +0000 (UTC) Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (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 DE89A156DD; Mon, 4 Mar 2024 07:39:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709537953; cv=none; b=cy9PQ/DfEm59i8GAD4MEf9gs3NlyKqn2tEfC3UxFqXEvHqKLecFECRFBwokSGRcn8ABX2lHeGWDg3f8L1IBZZXQpArO0ZYv/OzwhWZuuUb5E/oHcK11lp/MIuTUGskOjcI1Rl0AZ2LnXdE/wkxyxYnptCyHeYQoLGfisOmzGZxw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709537953; c=relaxed/simple; bh=VLjUG5/RbFyaBqGFUGG8p3fEzuef3DpGiYiEehefCEo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=s670lqZuw6yx3tbH91JBDsq6yA7SImgFrlNj3TQUy+1W2XoIWXmB4AhInMqfYcD94vOXlY9PaM2R8mjh9SKasfxddCRuyg23db2uNmsktMyOiKR367N2Lnq2x6qigHU+KI3IWj0yP49wX5UrE4c2CpUexHSo92zzuTprnVX5Jog= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Tp9Yh4sJTz4f3kkH; Mon, 4 Mar 2024 15:39:04 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 264F41A0172; Mon, 4 Mar 2024 15:39:08 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.101.6]) by APP4 (Coremail) with SMTP id gCh0CgDXKGuXeuVlWUH1Fw--.2277S5; Mon, 04 Mar 2024 15:39:07 +0800 (CST) From: Kemeng Shi To: tytso@mit.edu, adilger.kernel@dilger.ca Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, naresh.kamboju@linaro.org, daniel.diaz@linaro.org, linux@roeck-us.net, brauner@kernel.org Subject: [PATCH v4 3/3] ext4: initialize sbi->s_freeclusters_counter and sbi->s_dirtyclusters_counter before use in kunit test Date: Tue, 5 Mar 2024 00:35:43 +0800 Message-Id: <20240304163543.6700-4-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20240304163543.6700-1-shikemeng@huaweicloud.com> References: <20240304163543.6700-1-shikemeng@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: gCh0CgDXKGuXeuVlWUH1Fw--.2277S5 X-Coremail-Antispam: 1UD129KBjvJXoW7AFW3Jry5tFWxZw18XrWkJFb_yoW8Kr1xpF Wjkr10kF48CrZ7WrsxJr98X3WYgw4v9a4fK34xuryrAFWayryrAF1kKF15Cr4vgrW8XFnY vF1qg34UuF4rC37anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUB0b4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M280x2IEY4vEnII2IxkI6r1a6r45M2 8IrcIa0xkI8VA2jI8067AKxVWUWwA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK 0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4 x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l 84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I 8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AK xVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64 vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8G jcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2I x0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK 8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I 0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUIq2MUUUUU X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792580732006802900 X-GMAIL-MSGID: 1792580732006802900 Fix that sbi->s_freeclusters_counter and sbi->s_dirtyclusters_counter are used before initialization. Signed-off-by: Kemeng Shi Reported-by: Guenter Roeck --- fs/ext4/mballoc-test.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/fs/ext4/mballoc-test.c b/fs/ext4/mballoc-test.c index 4d9eb4807c98..19d74ebf5d83 100644 --- a/fs/ext4/mballoc-test.c +++ b/fs/ext4/mballoc-test.c @@ -45,6 +45,7 @@ static struct file_system_type mbt_fs_type = { static int mbt_mb_init(struct super_block *sb) { + ext4_fsblk_t block; int ret; /* needed by ext4_mb_init->bdev_nonrot(sb->s_bdev) */ @@ -69,8 +70,23 @@ static int mbt_mb_init(struct super_block *sb) if (ret != 0) goto err_out; + block = ext4_count_free_clusters(sb); + ret = percpu_counter_init(&EXT4_SB(sb)->s_freeclusters_counter, block, + GFP_KERNEL); + if (ret != 0) + goto err_mb_release; + + ret = percpu_counter_init(&EXT4_SB(sb)->s_dirtyclusters_counter, 0, + GFP_KERNEL); + if (ret != 0) + goto err_freeclusters; + return 0; +err_freeclusters: + percpu_counter_destroy(&EXT4_SB(sb)->s_freeclusters_counter); +err_mb_release: + ext4_mb_release(sb); err_out: kfree(sb->s_bdev->bd_queue); kfree(sb->s_bdev); @@ -79,6 +95,8 @@ static int mbt_mb_init(struct super_block *sb) static void mbt_mb_release(struct super_block *sb) { + percpu_counter_destroy(&EXT4_SB(sb)->s_dirtyclusters_counter); + percpu_counter_destroy(&EXT4_SB(sb)->s_freeclusters_counter); ext4_mb_release(sb); kfree(sb->s_bdev->bd_queue); kfree(sb->s_bdev); @@ -333,7 +351,7 @@ static int mbt_kunit_init(struct kunit *test) ext4_mb_mark_context, ext4_mb_mark_context_stub); - /* stub function will be called in mt_mb_init->ext4_mb_init */ + /* stub function will be called in mbt_mb_init->ext4_mb_init */ if (mbt_mb_init(sb) != 0) { mbt_ctx_release(sb); mbt_ext4_free_super_block(sb); @@ -534,6 +552,7 @@ static void test_mark_diskspace_used(struct kunit *test) struct test_range ranges[TEST_RANGE_COUNT]; int i; + mbt_generate_test_ranges(sb, ranges, TEST_RANGE_COUNT); ac.ac_status = AC_STATUS_FOUND;