Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp1031555lqt; Tue, 19 Mar 2024 10:40:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW5VIcpAskkjkgBbFRqFeZXc2qO++D4Fm+jmwdHJZz/q8T63FKu23h6KxqnRkEJUrnw7kEjwSbiolrFlrFc1ojkr0Fbr1wGAAkERaHtig== X-Google-Smtp-Source: AGHT+IG6NWF0qmxvuvAWcoTPcoy1zK7YdPt+/bAZaHC9Swqlpr9d80PAjpvrsLcbAP6pdx75wNav X-Received: by 2002:a05:620a:8cf:b0:789:d39a:485b with SMTP id z15-20020a05620a08cf00b00789d39a485bmr16440724qkz.44.1710870009082; Tue, 19 Mar 2024 10:40:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710870009; cv=pass; d=google.com; s=arc-20160816; b=F3nA4+MLsrKCfuxVZRZk7Zw5+scuFZ8A2SOoiWAfHUuajbsBTrWFtAwWQGROqmzM5P x6qyqK1BVGeNWxif+jO/7TtQFGuPnaZI1pevakJljTuqoe4z0ueGsU/ZDPqhxFvfxNtQ qBQ6OOWWRsUJ23OEm//AqHKPoCBXtKMsBycFqWaMKPHERfbreZ1zkzJZme13yf6wlAds 19reZszHXXCpjIJP3Vjvv/2C0RCSY/YrROZK/h9dKTnGvmrmPJeEQEW3WAdchlZnypMG mQLznkyXGoizk8pdAuy246pl4CaQbfRB4rorxSoZpFUcCEVJ7k2CxaNqOZ8tYGABjd7q NJHg== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=FbVTZraF0QJZsJx7Z45tBr7Rj39spiA67Pwo/WgWCSA=; fh=IvJDhn2XbJ55zxf0p/e9A+SWoPpre/ymwh9Q/MPTdCg=; b=AXTVH7IJkzD0+TgkR9NrgEU6ihCOiaAZ/InDwGAWs9EOhY4qDJ/M6i5Q2WX1xgQ0Tu pujmR3TwKPlNwjRkFmJozFbuQ6NJxY5Driuf0OFNxecYb0WhS6SCimhMjuql23cHStsV 1jBcCK2fNxveQalAPvVOiHk4AYC+06/mUPNRI4B19YiSMocshQ1qjLXfBVIje9xHg+Ss RTWpCcs086UFM6KjVGwKWaXwXxD46qu0pTQE9nYnJxyTOpMVjSbLxN5Z7QzEZiV5l5vS 3REkKPRjxy0NF3ghmwM+d1EFK+HChLOFcMLSEBdhem0DBnUNiIxouSFHSkWUXAWeBInE MyOQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Mlhro7yo; 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-107924-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107924-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 i13-20020a05620a404d00b00788624820cesi12796375qko.18.2024.03.19.10.40.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 10:40:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-107924-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=Mlhro7yo; 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-107924-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107924-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 BD7E11C22677 for ; Tue, 19 Mar 2024 17:40:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B389E25777; Tue, 19 Mar 2024 17:40:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Mlhro7yo" Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) (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 75F6925601 for ; Tue, 19 Mar 2024 17:40:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710870001; cv=none; b=pzy9WY4DLywYYTMuIyrEu1Mn0q6+4SNVHLrV64ZcN6V+8YUooS50JK2aeIMCR7mE7llczp/cZKunu2W9V10hc0GuETGlchkh/dKO5/Jar7o0lMSeAtjwu7Hvuakq1yqjguN4CEkF1xOp5gNoI3E0ZfgaGmEztw1fQ0A+x3LAxCE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710870001; c=relaxed/simple; bh=I30bldMoMsql+hzCHnhN/5IetJJd8PIn6Aa43/sDw8E=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=rwL/uifqof7EX2BWfDfPbQxHtv5zXlhzZpaEiyq2bFR35XB/jKRUJ4919FIy3g8MZIwV3w2s7B0/zmBujYMwDeFj8xLlFAvbcmRb9fB0f3/lsV0LkhIgnntV7wBfktacZOYau2NGj3ptrEH0ql1zT/pmjIXjYoNxmN7WI3O2VyI= 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=Mlhro7yo; arc=none smtp.client-ip=209.85.215.178 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-pg1-f178.google.com with SMTP id 41be03b00d2f7-5c6bd3100fcso3598879a12.3 for ; Tue, 19 Mar 2024 10:40:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710869999; x=1711474799; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=FbVTZraF0QJZsJx7Z45tBr7Rj39spiA67Pwo/WgWCSA=; b=Mlhro7yo5ABClgTDAprC3Xu8Z+DnusuY/jZIqqSdfMjXe25gLCuecJuLa3tB5Z1viU +yrdyoyk2/HqZWMYJ9IKEu6VAq5SFQz/nDl37+dGDZCyr2ToobrIw75IPZo/7Chs+JmR L3dazb9Bv44ZJm0hsSjn/KorBo3yUmqFyK2YYQPVcRs99jvBD4QmxWWuEaUAO2RDqq6K kOBqYFVKYs+Tcy6oz6CSL3LgSfA2NJEx0pRYc2G3nTiUE/rWqMhg3cq3aSjegHlxLYpr aYyNjKW9+jZUPUpuP6PU6E3LVuAJAsk8Tq5w+5ouayk8Z95acZtmd2dGSzevaEEoy0U5 YaSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710869999; x=1711474799; 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=FbVTZraF0QJZsJx7Z45tBr7Rj39spiA67Pwo/WgWCSA=; b=w58siXabdW6OpUnM8sXALY02pM+pyllhXNvAPXGkkCNv61XYTHRieOmNjwm26HKHVz 3Mk5suJhWcqu+RkGtZvLINK7WZpzCNKzrOe4f1ElTnydhxyYBi0drdR2XWvIT/oWaIBk Hju/TRLn/6IRotBT5+i8PjfZEoj+o5rMtZVW5QcILPJnul/x98GmHrhvG7Wv/lZCS9qI NNXPXaCchWzVCQHaKmu+nFyxkKZ7NxKZLzRcptUtnQ58Z/4OST5wjzrf9CdutQ7PTSAd G38+42OMe8g1te/xuw0otRHcDZvtVNwFjl2qZ84/lm3eu0PmKGGpOfm/6ACiX+W4WQKA dJCA== X-Gm-Message-State: AOJu0YyFQXgXPYIf3ZU7ciseShWuPFURFGQh0u333sK9YxNi0WEJUpTe Cumb6Oia7SaxbuY0JwAaXFM9SSTdRT+kpRCYS3QcX2TlJAhktH0honDK5cBC X-Received: by 2002:a05:6a20:94cf:b0:1a3:6ee9:305 with SMTP id ht15-20020a056a2094cf00b001a36ee90305mr4484410pzb.2.1710869999244; Tue, 19 Mar 2024 10:39:59 -0700 (PDT) Received: from daehojeong-desktop.mtv.corp.google.com ([2620:0:1000:8411:ce48:f01a:1f52:5e0a]) by smtp.gmail.com with ESMTPSA id i185-20020a62c1c2000000b006e583a649b4sm10392921pfg.210.2024.03.19.10.39.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 10:39:58 -0700 (PDT) From: Daeho Jeong To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com Cc: Daeho Jeong Subject: [PATCH v3] f2fs: prevent writing without fallocate() for pinned files Date: Tue, 19 Mar 2024 10:39:55 -0700 Message-ID: <20240319173955.4090079-1-daeho43@gmail.com> X-Mailer: git-send-email 2.44.0.291.gc1ea87d7ee-goog Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Daeho Jeong In a case writing without fallocate(), we can't guarantee it's allocated 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 == F2FS_GET_BLOCK_DIO))) { - if (unlikely(f2fs_cp_error(sbi))) { + (is_hole || (f2fs_lfs_mode(sbi) && flag == F2FS_GET_BLOCK_DIO && + !f2fs_is_pinned_file(inode)))) { + if (unlikely(f2fs_cp_error(sbi)) || + (f2fs_is_pinned_file(inode) && is_hole && + flag != F2FS_GET_BLOCK_PRE_DIO)) { err = -EIO; goto sync_out; } @@ -3378,6 +3381,8 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi, f2fs_map_lock(sbi, flag); locked = true; } else if ((pos & PAGE_MASK) >= i_size_read(inode)) { + if (f2fs_is_pinned_file(inode)) + return -EIO; f2fs_map_lock(sbi, flag); locked = true; } @@ -3407,6 +3412,11 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi, if (!f2fs_lookup_read_extent_cache_block(inode, index, &dn.data_blkaddr)) { + if (f2fs_is_pinned_file(inode)) { + err = -EIO; + goto out; + } + if (locked) { err = 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 = file_inode(vmf->vma->vm_file); struct f2fs_sb_info *sbi = F2FS_I_SB(inode); struct dnode_of_data dn; - bool need_alloc = true; + bool need_alloc = !f2fs_is_pinned_file(inode); int err = 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 = 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 = f2fs_get_dnode_of_data(&dn, page->index, LOOKUP_NODE); 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 4KB. */ map.m_lblk = F2FS_BLK_ALIGN(pos); map.m_len = F2FS_BYTES_TO_BLK(pos + count); -- 2.44.0.291.gc1ea87d7ee-goog