Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp3499837lqp; Tue, 26 Mar 2024 10:42:23 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWHoO5KXkp10Yemjw0gXYhhYnqafVPrbP3xnhjR8GonIDPsvSTR1JsktFsWvu5DmGjWGBXEWRSUb6vazX3mE2K+nyyyhODfQcReMZ9QCA== X-Google-Smtp-Source: AGHT+IHEp5vl7Qs9y99dC964dznrFixVahcoGTvrhWfkhUGDg+iEuhID4W5NnJCIP+yc/7mUDi6a X-Received: by 2002:a17:906:580e:b0:a4d:fdfb:3d01 with SMTP id m14-20020a170906580e00b00a4dfdfb3d01mr230904ejq.3.1711474943406; Tue, 26 Mar 2024 10:42:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711474943; cv=pass; d=google.com; s=arc-20160816; b=t8ZrHq3yE/gmGlEcFKCjO7rvoWOUp9OBkBksXumKzoaWpGCi82ba0XNR8YckAQCYvF 37UX1W0lgZ8323hAikGvYrc9nbA2i55VPGDf5FHkaPGiKxGgdz8jmyyqK1RpvIp/1tph hfQBi/vgqDV8y0cESj1OFbxF3rd5Pt7gq0devxopcoyVdiarllQ2Q2bR2xTDilg/mAhH 1pC38MgaDGdw6taqTyOCj0kBd19RuTKdVCbUbCvwNR83vY9ny5BmXbCjBrApnDTuHXET PJqFICdn4oADe9XdTFFz+ngxWMbsePI76aw7/T5JhLHSjfEtR73wnbSSltOfHsyMiOpO /SuQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=bQ35C+kL3axh6L7EwSqgU9ptD4Ff3HJAuCiRN7ziw38=; fh=sPilOYAT4QfMgYxGH2LjRrcqbLUzvrQqMQUicHZMufQ=; b=uE1HdqBowJN/zsSv1qM9ZXy61FX8M97JaVrtzmC9NivCansxsCM1MFMxX9CYydH5OD 2yOtW/GWi2yDS8kuegOPMvySg7hhcI3wb6MVnft7CupPJ/TzZPt4v8tDFxPZcUAPHeNZ 7Vnv+OIdsi1IOqtMUbNQiDhg+0AilKjOa1dP4WUmp6mv4Dsap2ot91LQE3eaD2XjY1LK CZSqFgBkg0gytJKgJVThWT0RTx0YjnG5dj4/UDK+6RQhqP13wDANXPJycBCQrIFzT154 Hy7Lebe6BvFevNR6canqE08IFtgebDquub/TdLVc12CZnD6nms8ZUa5WxiRKW8hczccp XYKw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="LoQ/MSOZ"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-119609-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119609-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 r1-20020a170906280100b00a46485678b2si3699180ejc.651.2024.03.26.10.42.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 10:42:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-119609-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=@gmail.com header.s=20230601 header.b="LoQ/MSOZ"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-119609-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-119609-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 640E71F83A89 for ; Tue, 26 Mar 2024 17:35:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7C0C91C6A0; Tue, 26 Mar 2024 17:34:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LoQ/MSOZ" Received: from mail-vk1-f177.google.com (mail-vk1-f177.google.com [209.85.221.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B75B420DFC for ; Tue, 26 Mar 2024 17:34:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711474497; cv=none; b=Yw2KDPaTqtHZzJcd+KX1lCGln94sL3zeiTENEXqaHU+Ozky5aoff6ZN/ECXzjHD0IlvJfjA/Tpyno9fb8lnIjibvkJwqvC6JYPJp7zrCK4QkyF/avpIPjabAF3sirO2KzXcB9hh15qsnolYIeDDC3QPnRSHw2K0dULbtmnMpIBQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711474497; c=relaxed/simple; bh=m2w3ra/vLTtdfASbbEeXbAqU4LoxnYVueub8n5/zmtc=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=IvVgem/HoI5fSlrzG2lSXcAz98+HgOeq4Y94GFqB3sM0xIIEQJCxTEzra1+lOWILEkgnxL9S9ZvpCwanWRRNOWlFb89Y8tYhn0cl/9zjX1+CQFilvL21KmUigyzgUZIbduHAtYxjv33khyhS+j9GNVU5Jyfw9G87Jxvb2PLQR28= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LoQ/MSOZ; arc=none smtp.client-ip=209.85.221.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-vk1-f177.google.com with SMTP id 71dfb90a1353d-4d436ab8a36so2068359e0c.0 for ; Tue, 26 Mar 2024 10:34:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711474494; x=1712079294; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=bQ35C+kL3axh6L7EwSqgU9ptD4Ff3HJAuCiRN7ziw38=; b=LoQ/MSOZV0+LRQAoK1Ah643sZ5C5gz6dB7RmxkZ9YRY6L2PThiGpcevvK0cX1W0ZR9 Lc7604IjV3nvTt+ozYrngOFT+hLQt2yh5/CdULsz3FLyH9Tm9j9mn9IcvuOv3Mjw1zl9 1XGyKGIPbGthLYRqGjZ8fg0CVVX11AKppQuztf34h1Ubt3wTckK+Js0aRyZdxqkM0pg8 HwA9JxNxCH7yfunPe162JkqQqgczpdzWY17tYcdzF3VgtW10A5yqIPDcYqoXc/49UISL N/wr8v0D7patIbU0y/YkmG3HgKsP/3aE4cR0NgaiBAH2BOfA9dr5AYmBBQJLFSw84WNp tk2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711474494; x=1712079294; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bQ35C+kL3axh6L7EwSqgU9ptD4Ff3HJAuCiRN7ziw38=; b=HzhWvI/DXRJSmKpRv42U8rtgTtJOv8BNBP46cAr/VNgMzpL9Yzy2jbIaCUh3L72HFn 7J03tnLKdVKZhYqNUI9syC5vVSxmI8hJTTNnqF64wCZbqi7kSDiPvrwKGabLeTBRimn0 YDiju3sIf1H806VYQZVQOEQymYjTfJV0P4V1LXRorBO1ze/cfkF9Pj4qMWIx62qrQa8B 894raADGXaFY7ByjpUSus5ifBR9dDEOQf6LX+JtJtOppQOsCrwTjNkDR5pdA1r2Ubrf+ tTQT9xiV1XueEQqCjSsmUsS1a/Dub84TXn0e7yhXs+S8ucw/hoU6wkIJ5DQKaP1ex3uw 5Qrg== X-Gm-Message-State: AOJu0YwHLtdbH8zIcEIy3ODEKwA6MXPQD6kvVjRphtEUV8nOip/svYXd ks1jDNJJ6tS0IDZXOmfdYFsdKP5kydnILuRLgvuh1tGa/EkEyyqYZGCRB4pHeAClxNvhOoPodJW TPxMSXxQDWb5EMShf7hfLkypxEBU= X-Received: by 2002:a05:6122:1d02:b0:4d8:79c1:2a21 with SMTP id gc2-20020a0561221d0200b004d879c12a21mr9063727vkb.7.1711474494503; Tue, 26 Mar 2024 10:34:54 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240319212316.4193790-1-daeho43@gmail.com> <712f380c-68ef-4743-bd9b-7342e838ced7@kernel.org> <30419139-6fdd-48df-b32a-9db7575cebb8@kernel.org> In-Reply-To: <30419139-6fdd-48df-b32a-9db7575cebb8@kernel.org> From: Daeho Jeong Date: Tue, 26 Mar 2024 10:34:43 -0700 Message-ID: Subject: Re: [f2fs-dev] [PATCH v3] f2fs: prevent writing without fallocate() for pinned files To: Chao Yu Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com, Daeho Jeong Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Mar 25, 2024 at 8:39=E2=80=AFPM Chao Yu wrote: > > On 2024/3/25 23:02, Daeho Jeong wrote: > > On Fri, Mar 22, 2024 at 9:26=E2=80=AFPM Chao Yu wrote= : > >> > >> On 2024/3/21 1:42, Daeho Jeong wrote: > >>> On Wed, Mar 20, 2024 at 2:38=E2=80=AFAM Chao Yu wro= te: > >>>> > >>>> On 2024/3/20 5:23, Daeho Jeong wrote: > >>>>> From: Daeho Jeong > >>>>> > >>>>> In a case writing without fallocate(), we can't guarantee it's allo= cated > >>>>> in the conventional area for zoned stroage. > >>>>> > >>>>> Signed-off-by: Daeho Jeong > >>>>> --- > >>>>> v2: covered the direct io case > >>>>> v3: covered the mkwrite case > >>>>> --- > >>>>> fs/f2fs/data.c | 14 ++++++++++++-- > >>>>> fs/f2fs/file.c | 16 ++++++++-------- > >>>>> 2 files changed, 20 insertions(+), 10 deletions(-) > >>>>> > >>>>> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c > >>>>> index c21b92f18463..d3e5ab2736a6 100644 > >>>>> --- a/fs/f2fs/data.c > >>>>> +++ b/fs/f2fs/data.c > >>>>> @@ -1584,8 +1584,11 @@ int f2fs_map_blocks(struct inode *inode, str= uct f2fs_map_blocks *map, int flag) > >>>>> > >>>>> /* use out-place-update for direct IO under LFS mode */ > >>>>> if (map->m_may_create && > >>>>> - (is_hole || (f2fs_lfs_mode(sbi) && flag =3D=3D F2FS_GET_B= LOCK_DIO))) { > >>>>> - if (unlikely(f2fs_cp_error(sbi))) { > >>>>> + (is_hole || (f2fs_lfs_mode(sbi) && flag =3D=3D F2FS_GET_B= LOCK_DIO && > >>>>> + !f2fs_is_pinned_file(inode)))) { > >>>>> + if (unlikely(f2fs_cp_error(sbi)) || > >>>>> + (f2fs_is_pinned_file(inode) && is_hole && > >>>>> + flag !=3D F2FS_GET_BLOCK_PRE_DIO)) { > >>>>> err =3D -EIO; > >>>>> goto sync_out; > >>>>> } > >>>>> @@ -3378,6 +3381,8 @@ static int prepare_write_begin(struct f2fs_sb= _info *sbi, > >>>>> f2fs_map_lock(sbi, flag); > >>>>> locked =3D true; > >>>>> } else if ((pos & PAGE_MASK) >=3D i_size_read(inode)) { > >>>>> + if (f2fs_is_pinned_file(inode)) > >>>>> + return -EIO; > >>>>> f2fs_map_lock(sbi, flag); > >>>>> locked =3D true; > >>>>> } > >>>>> @@ -3407,6 +3412,11 @@ static int prepare_write_begin(struct f2fs_s= b_info *sbi, > >>>>> > >>>>> if (!f2fs_lookup_read_extent_cache_block(inode, index, > >>>>> &dn.data_blkaddr))= { > >>>>> + if (f2fs_is_pinned_file(inode)) { > >>>>> + err =3D -EIO; > >>>>> + goto out; > >>>>> + } > >>>>> + > >>>>> if (locked) { > >>>>> err =3D f2fs_reserve_block(&dn, index); > >>>>> goto out; > >>>>> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c > >>>>> index 82277e95c88f..4db3b21c804b 100644 > >>>>> --- a/fs/f2fs/file.c > >>>>> +++ b/fs/f2fs/file.c > >>>>> @@ -57,7 +57,7 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_= fault *vmf) > >>>>> struct inode *inode =3D file_inode(vmf->vma->vm_file); > >>>>> struct f2fs_sb_info *sbi =3D F2FS_I_SB(inode); > >>>>> struct dnode_of_data dn; > >>>>> - bool need_alloc =3D true; > >>>>> + bool need_alloc =3D !f2fs_is_pinned_file(inode); > >>>> > >>>> Will this check races w/ pinfile get|set? > >>> > >>> Do you mean "set/clear" case? I believe "set" case is okay, since we > >> > >> Yup, > >> > >>> can't set if the inode already has a data block. For "clear" case, I > >> > >> However, we can set pinfile on written inode in regular block device: > > > > You're right. I missed it. Maybe I think we should keep the concept > > consistent across devices regardless of zoned storage support. How > > about preventing file pinning for already written inodes across all > > device types? I am changing the pinfile concept by allowing the users > > I'm okay with that, or we can tries to migrate data block of target file > from seq-zone to conv-zone or regular-device before setting it w/ pin fla= g... I can't see lots of benefits by supporting file pinning for pre-written inodes, while the design can become complicated. Since we consolidate the way to support file pinning as fallocate() before using it, we might as well not support pre-written inodes. > > Thanks, > > > to write on only fallocate()-ed space. > > > >> > >> if (f2fs_sb_has_blkzoned(sbi) && F2FS_HAS_BLOCKS(inode)) { > >> ret =3D -EFBIG; > >> goto out; > >> } > >> > >> Should we add the logic only if blkzoned feture is enabled? > >> > >>> believe mkwrite failure is okay in racy conditions caused by clearing > >>> the pin flag. What do you think? > >> > >> Or we can use filemap_invalidate_lock() in f2fs_ioc_set_pin_file() to > >> avoid the race condition? > >> > >> Thanks, > >> > >>> > >>>> > >>>> Thanks, > >>>> > >>>>> int err =3D 0; > >>>>> vm_fault_t ret; > >>>>> > >>>>> @@ -114,19 +114,15 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct= vm_fault *vmf) > >>>>> goto out_sem; > >>>>> } > >>>>> > >>>>> + set_new_dnode(&dn, inode, NULL, NULL, 0); > >>>>> if (need_alloc) { > >>>>> /* block allocation */ > >>>>> - set_new_dnode(&dn, inode, NULL, NULL, 0); > >>>>> err =3D f2fs_get_block_locked(&dn, page->index); > >>>>> - } > >>>>> - > >>>>> -#ifdef CONFIG_F2FS_FS_COMPRESSION > >>>>> - if (!need_alloc) { > >>>>> - set_new_dnode(&dn, inode, NULL, NULL, 0); > >>>>> + } else { > >>>>> err =3D f2fs_get_dnode_of_data(&dn, page->index, LO= OKUP_NODE); > >>>>> f2fs_put_dnode(&dn); > >>>>> } > >>>>> -#endif > >>>>> + > >>>>> if (err) { > >>>>> unlock_page(page); > >>>>> goto out_sem; > >>>>> @@ -4611,6 +4607,10 @@ static int f2fs_preallocate_blocks(struct ki= ocb *iocb, struct iov_iter *iter, > >>>>> return ret; > >>>>> } > >>>>> > >>>>> + /* For pinned files, it should be fallocate()-ed in advance. = */ > >>>>> + if (f2fs_is_pinned_file(inode)) > >>>>> + return 0; > >>>>> + > >>>>> /* Do not preallocate blocks that will be written partially= in 4KB. */ > >>>>> map.m_lblk =3D F2FS_BLK_ALIGN(pos); > >>>>> map.m_len =3D F2FS_BYTES_TO_BLK(pos + count);