Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp1679610lqt; Wed, 20 Mar 2024 10:42:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWEji0N/Qq6VhHbBTWeNQGt9+UUlmTomNdsMJSuOAuotBiwgDdTu+gPI3EKOYvoSKMsrDwDcx/wiAfkw5l60ZJdaoeD6aoDuJc0qtr97g== X-Google-Smtp-Source: AGHT+IEnThnKxSej5UH6YkWpgQ7O37g6IBYEpuMpA9doptFIe6zOtSkDVVMcT7WASk2n4JehJ5Kd X-Received: by 2002:ac8:7f93:0:b0:430:d658:8b7b with SMTP id z19-20020ac87f93000000b00430d6588b7bmr10978286qtj.14.1710956541906; Wed, 20 Mar 2024 10:42:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710956541; cv=pass; d=google.com; s=arc-20160816; b=J1RO4YKvZsdqXwYKeN73e4alEawY5ZITeJE7BAmD3d8RvTPbXBpUSQQijh50AQao79 IkTUk9KCbZv3c/1BT2Xjpf8WqtDIoiJnP/lILXVIU1bPDjF1EKVR/KUpPdEx+uV9rwFt YQi05/D+jr6qVAuoNDcSsny0xj72MT7iFiIlJqXnp5cDhh08vGZfevS6jJ1CVLTdT+uK K776gQhYOC8xsaYkQmdXtjTq+hryUgmYOeB9RIq8WkaucANJbyAjSLyxSUvwJIYrPoew ETpio2NjH0yQmQEskF16tiLcpvU9CExf3zwoizVWZ10aSAkLvHdf3X+S2vGWYwK/jEQM yIwQ== 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=NW19ZZi2sVI9kzIhS7t3Wxp6wjDVebKp4FeXycGbrmk=; fh=sPilOYAT4QfMgYxGH2LjRrcqbLUzvrQqMQUicHZMufQ=; b=eh0PxAe6dnBkvX5g0O//mXbyVgPt2pEFSYbLQzM6+Rh3zd7fA+/guX1Lji7mDh/9L2 wMISvBBVXelrNNXPIc+kA7JAeImOYAfL6ijzfLEkFd4X4+pKenC5+VrO7xOfbu/40MTU 7eie660mQHyRBtpsDRHpK0O2LaUZp07ncWJbmDS+11JjhyZ0MVFq3IAnosTWJALnh8CD fn0sHSgG36Di9iULGd2oyGs8LQT6S8n8kQpWKGH5PsJlyRgkJfjmszu9TBp26iCqE4Pc RliepDLVkfGZ6+TCSMj0k3mLAdc/FyPnSH1Po4C5B7SpASQ4l8iytaJ21Exi/v/Uj4Kt FcSg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=RlxGXUjt; 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-109246-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-109246-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id m15-20020a05622a054f00b004310bd08998si1463364qtx.548.2024.03.20.10.42.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Mar 2024 10:42:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-109246-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=RlxGXUjt; 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-109246-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-109246-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 7EBA81C228D4 for ; Wed, 20 Mar 2024 17:42:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 60A846A33E; Wed, 20 Mar 2024 17:42:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RlxGXUjt" Received: from mail-ua1-f49.google.com (mail-ua1-f49.google.com [209.85.222.49]) (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 D9965628 for ; Wed, 20 Mar 2024 17:42:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710956535; cv=none; b=iY2maeivyxMapfPSrEqjQE15V92w95OQtswZZInH8ykj+e7BzyEVTlS5l/QecVRbkZ7a2prmU4rvzw/2EBkv2E7+L8Q7Yl4NAs5c6SmXUt4mRXJ1hl30BWQXIGMC4I5UY4B4SgWzEK8FSwAgLFfuNYIj6HA2bh65BtIV7nvmYSY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710956535; c=relaxed/simple; bh=VhGg694ao/0WXM3Z9YmE2+/9/baWtANWAVHD4wIPwk8=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=l9exQgPTTXpxMZvHyGa5Mwhgpahwt1huo6wxzCst4wOsFuDFEUgzA7jO5M0G3hAnAQCj2ElNDYcoCVH3yL5/aFYHl/v7cKbbjUBvY6sZ0T2dBtXIw5g4MFeYAICtRkqHH8fgw6OmCPRgG0aTNCvGoNcTZv6iSYXSsSSY5stIGxs= 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=RlxGXUjt; arc=none smtp.client-ip=209.85.222.49 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-ua1-f49.google.com with SMTP id a1e0cc1a2514c-7dec16fc4b2so34759241.3 for ; Wed, 20 Mar 2024 10:42:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710956533; x=1711561333; 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=NW19ZZi2sVI9kzIhS7t3Wxp6wjDVebKp4FeXycGbrmk=; b=RlxGXUjtzNYbZjyJhyDQ7o7Y0e6L8PPERcPw3qkmX8rDZP50GKXh9w17OAVkPcptC9 A6RJJ2nT9YEKLSyiXdBMtqAJewzq75lse/TRfYEQ1OQS0KLA/DM63WX/6Hva4HDgDhD+ xEtH6cf5hav5uOeAvp0O3nnvGC2kMs8ttUEMfwdSgL+FtpjhdTFCKtXbrqsHaPM0cpa4 xMuBX6Jk1kr8Ht2VF3sS77+xCmmILAnEURfLnrdgmNZKdIM1dPlELzxrdrmnr+YmF9/i bSureDhwqPQmaaYcxjF16F3L7YsbbiS/DEJ1fqXACZMmzrQCbH4CLEWCp+ZIB5BnhmrB BKFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710956533; x=1711561333; 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=NW19ZZi2sVI9kzIhS7t3Wxp6wjDVebKp4FeXycGbrmk=; b=WpDEzd+PJbUQvFF9stMVfbuTQ9jwdbrlbxPFcv5KtcSm9WjRcnadw5p22n9QeC4SMq qM9kKff9+zzx6EkSVTScttPoQWeL8SIbtn5PfQhb+LRz7aYxqQ/QWPuzKmoKAc8AxDMQ mipJF9qqGcgJQ0yC8PHeZihRjYhcgo/YnUbWZRadQdHhA2uUi//A9IstL6l0J2J/Tz4X JQVqMJaN6Nc7rHZTFAv098cJ99lp2WanXmlMALE/KUgwxRsTmn+zkcHcFH484bY7bFk9 zpCpPw/52Zn9fgsj/Al1VgXVR29GpAkCK/vCjG5GiV2j9yEMSMKJyHkRZARsNi1ZIOjs WseA== X-Gm-Message-State: AOJu0YxPhpUPOZH3pe4bO1zyv3eCE50XWGeP+I2H3sriDR7Ei8Fzr5GE YQshS//zLi03kS5fPr7LFV8emYDlcbiiUUMSy/ruchPesLbdbajt4JLGaD3RDrpJlbOw5aSLKuh u79DL2rObjV7cIse3hzjzP8U0+fM= X-Received: by 2002:a67:b64b:0:b0:476:5404:5f11 with SMTP id e11-20020a67b64b000000b0047654045f11mr15013127vsm.25.1710956532744; Wed, 20 Mar 2024 10:42:12 -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> In-Reply-To: <712f380c-68ef-4743-bd9b-7342e838ced7@kernel.org> From: Daeho Jeong Date: Wed, 20 Mar 2024 10:42:01 -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 Wed, Mar 20, 2024 at 2:38=E2=80=AFAM Chao Yu wrote: > > On 2024/3/20 5:23, Daeho Jeong wrote: > > From: Daeho Jeong > > > > In a case writing without fallocate(), we can't guarantee it's allocate= d > > 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, struct = 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_BLOCK= _DIO))) { > > - if (unlikely(f2fs_cp_error(sbi))) { > > + (is_hole || (f2fs_lfs_mode(sbi) && flag =3D=3D F2FS_GET_BLOCK= _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_inf= o *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_sb_in= fo *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_faul= t *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 can't set if the inode already has a data block. For "clear" case, I believe mkwrite failure is okay in racy conditions caused by clearing the pin flag. What do you think? > > 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, LOOKUP_N= ODE); > > f2fs_put_dnode(&dn); > > } > > -#endif > > + > > if (err) { > > unlock_page(page); > > goto out_sem; > > @@ -4611,6 +4607,10 @@ static int f2fs_preallocate_blocks(struct kiocb = *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 4K= B. */ > > map.m_lblk =3D F2FS_BLK_ALIGN(pos); > > map.m_len =3D F2FS_BYTES_TO_BLK(pos + count);