Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3237865ybb; Sun, 22 Mar 2020 19:13:11 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuLhtcJl4JBHWig7E9w/fOwxh/DhM3mPG58L7FHb3+JUSkXpOY0p9l0Wv7H2bKOUrcmhynu X-Received: by 2002:aca:39d5:: with SMTP id g204mr14809692oia.93.1584929591076; Sun, 22 Mar 2020 19:13:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584929591; cv=none; d=google.com; s=arc-20160816; b=yBxWlKkpR6rCUsZnRJLNqrUntEf1PmYjR+owgtTuVL6Ee371DLxqMyyCa6u+A9Bd+l 8LU6fQncFNnyAWqhCQDwriEt4XmaC18zwUnPTjIHjy2d3CqKQ0/DbRODSq8yT6uk/80f KX55ib53BjsScgRGSLWz/KdGiMfhMBXuPUGkjRQ16xVOvK9UXHcvqI+zWkyhNXzm2ACU pwfFCbO6zSak0o5CR+7HC6vwX48vQiSR0eMUucCBDrcr7QlmOsAxxUl1qdG5XqIWCQSf aWyuo/IuJwNsK5n969l4yaPcJds+Bdnq4hgJf19j1Aw7JilHwr4d7aoJlDbAsD8+vmt4 5yxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject; bh=uXsqFrQoV3CMZMJeow3Kc8jOcMTg9VilywIE+iHZYMA=; b=FZ2NmMUX3x68Z0qDVX0Q0v1LlIq+2h6Rqn8t1jW+4S3JJwkQzGOK6rqiVAZFRSv003 EIOIBF5yVIw8AlFu/ykILN3PCscCx0Dj82xdr6oXTSTuxuoDjm44oPiAOou6j32pu7Dd h7sB8gxQuIbqemX3Ark4SaBE4robKStb6qvPEp0el1pnZ9v1juFA1XDOv16lVQ0ItDQN 2yMWjxdpq7fY5oXoEhe86XjCCP8yoQPovkFkdeX0AfoSOM4UxDeIPL/KrI8DH1lhpC3t 8bTBAzj3h90WtNPWXvRZ9Bl0v89lQX+hqnuEs2j8KtHB6UaQ1Tgih+nD4ef7h5dbmTKT clGg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u10si6883075otj.235.2020.03.22.19.12.58; Sun, 22 Mar 2020 19:13:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727117AbgCWCLI (ORCPT + 99 others); Sun, 22 Mar 2020 22:11:08 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:45488 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726951AbgCWCLI (ORCPT ); Sun, 22 Mar 2020 22:11:08 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 977822BEDAB46AD93768; Mon, 23 Mar 2020 10:09:52 +0800 (CST) Received: from [10.134.22.195] (10.134.22.195) by smtp.huawei.com (10.3.19.206) with Microsoft SMTP Server (TLS) id 14.3.487.0; Mon, 23 Mar 2020 10:09:49 +0800 Subject: Re: [PATCH v3] f2fs: fix potential .flags overflow on 32bit architecture To: =?UTF-8?Q?Ond=c5=99ej_Jirman?= , , , , References: <20200323012519.41536-1-yuchao0@huawei.com> <20200323015036.pniupuucfl3dug4m@core.my.home> From: Chao Yu Message-ID: <1d861a2e-0045-af0c-1f5b-c45b774c83f6@huawei.com> Date: Mon, 23 Mar 2020 10:09:48 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20200323015036.pniupuucfl3dug4m@core.my.home> Content-Type: text/plain; charset="UTF-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.134.22.195] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Ondřej, On 2020/3/23 9:50, Ondřej Jirman wrote: > Hello Chao Yu, > > On Mon, Mar 23, 2020 at 09:25:19AM +0800, Chao Yu wrote: >> [snip] >> >> +static inline void __set_inode_flag(struct inode *inode, int flag) >> +{ >> + test_and_set_bit(flag % BITS_PER_LONG, >> + &F2FS_I(inode)->flags[BIT_WORD(flag)]); > > This can simply be: > > test_and_set_bit(flag, F2FS_I(inode)->flags); > > all of these bitmap manipulation functions already will do the > right thing to access the correct location in the flags array: > > https://elixir.bootlin.com/linux/latest/source/include/asm-generic/bitops/atomic.h#L32 > > see BIT_MASK and BIT_WORD use in that function. Oops, most f2fs bitmap check uses the same form, I missed this case.... > >> +} >> + >> static inline void set_inode_flag(struct inode *inode, int flag) >> { >> - if (!test_bit(flag, &F2FS_I(inode)->flags)) >> - set_bit(flag, &F2FS_I(inode)->flags); >> + __set_inode_flag(inode, flag); >> __mark_inode_dirty_flag(inode, flag, true); >> } >> >> static inline int is_inode_flag_set(struct inode *inode, int flag) >> { >> - return test_bit(flag, &F2FS_I(inode)->flags); >> + return test_bit(flag % BITS_PER_LONG, >> + &F2FS_I(inode)->flags[BIT_WORD(flag)]); > > ditto > >> } >> >> static inline void clear_inode_flag(struct inode *inode, int flag) >> { >> - if (test_bit(flag, &F2FS_I(inode)->flags)) >> - clear_bit(flag, &F2FS_I(inode)->flags); >> + test_and_clear_bit(flag % BITS_PER_LONG, >> + &F2FS_I(inode)->flags[BIT_WORD(flag)]); > > ditto > > I'm going to test the patch. It looks like that this was really > the root cause of all those locking issues I was seeing on my > 32-bit tablet. It seems to explain why my 64-bit systems were > not affected, and why reverting compession fixed it too. > Great job figuring this out. > > I'll let you know soon. Great, hoping this patch can fix the issue this time. Thanks anyway for supporting on troubleshooting this issue. Thanks, > > thank you and regards, > o. > >> __mark_inode_dirty_flag(inode, flag, false); >> } >> > . >