From patchwork Thu Mar 25 14:03:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 12164165 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3FC01C433DB for ; Thu, 25 Mar 2021 14:04:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 13F9861A21 for ; Thu, 25 Mar 2021 14:04:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231344AbhCYOEL (ORCPT ); Thu, 25 Mar 2021 10:04:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231281AbhCYOD7 (ORCPT ); Thu, 25 Mar 2021 10:03:59 -0400 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42DF1C06174A for ; Thu, 25 Mar 2021 07:03:59 -0700 (PDT) Received: by mail-pf1-x429.google.com with SMTP id m11so2154616pfc.11 for ; Thu, 25 Mar 2021 07:03:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Xy3iwbs7ggKcHUTrKKUPiIQ1zW95J0vGHjor1UXhyVA=; b=f/CDkqJO+shcNEUTLjm2T1gyGhLHN+yBOx9++yZwvwqvaaNgH2ve9xy8h/ZMSxHjfd bfho88Xe+RAi474G2JV5UQ7ZjpiTdbwZ8OJsYv+iYuspjeeMJTqTQ97mM/Wpdk71IGAr lLS5lI0DIv1RfDeDmMlzRb6UMda54fwyJlIXDtEwV3PELuFT5Rh24tinHsUxLSccN+Uw eX2Rw5Go44X4i2sNtgovzFJoahp5vT9uub3zjQBQpYDJhrX0ACIyYB+KqyeTXsa8R7qK TT/CVWb4Z2Xo6+uCBEm1MAfoldMiRko90+ud31Ts1ED9vgpWr6ONRCXJqXbdUZ+6jDd8 EwMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Xy3iwbs7ggKcHUTrKKUPiIQ1zW95J0vGHjor1UXhyVA=; b=ZrqJbXGmefNHEz1AKGWYbGMzw9kbh7B5gIpxZrELSGEDQmNgVE9EG06PnHVcePDXjz fFzj4bdLvfV6/G9kEpK8FrkIP9PcscVFCXWxbxUqgKvKUo3oJ8uW3EW5uy64kQ1vh2Bs guqTEsBzQ/hTrfLCS4aFm97iTXi6TdQBMehycIZz+IZcEmVdkGM+ihxl/ccw8xtF3wBd Ih0av11CBp/sZOqJLoC0/nFHPXp+cjo8BdDMcE6jbb6AlGKDin/JPZft4ekUEKEPp0/W gBIGGlTmQqbaaJmPpViFOa0gfNk8y/jZCEfhC/bZxn6/uB/U5Duu+Me/b3p0iBOHTYkD dUYg== X-Gm-Message-State: AOAM531XFz8qFl9pvWkFnUHaAHNhlBMA4C9rHbabPiQ/iYMisXhLL5YX tuSE+hjUfv+ewJwRgE5bHOvDMLSARt4= X-Google-Smtp-Source: ABdhPJy1ffgZ0y5kWtv5A9DOzSV7ZVxZkgNvZsiBqEWSZ0kI7Nu+5zCxbvoeMO3+e9sGq/r10gvVEw== X-Received: by 2002:a63:1e20:: with SMTP id e32mr7634678pge.345.1616681038506; Thu, 25 Mar 2021 07:03:58 -0700 (PDT) Received: from localhost.localdomain ([122.171.175.121]) by smtp.gmail.com with ESMTPSA id x2sm5876379pgb.89.2021.03.25.07.03.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Mar 2021 07:03:58 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , djwong@kernel.org Subject: [PATCH 1/2] xfs: Initialize xfs_alloc_arg->total correctly when allocating minlen extents Date: Thu, 25 Mar 2021 19:33:38 +0530 Message-Id: <20210325140339.6603-1-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org xfs/538 can cause the following call trace to be printed when executing on a multi-block directory configuration, WARNING: CPU: 1 PID: 2578 at fs/xfs/libxfs/xfs_bmap.c:717 xfs_bmap_extents_to_btree+0x520/0x5d0 Call Trace: ? xfs_buf_rele+0x4f/0x450 xfs_bmap_add_extent_hole_real+0x747/0x960 xfs_bmapi_allocate+0x39a/0x440 xfs_bmapi_write+0x507/0x9e0 xfs_da_grow_inode_int+0x1cd/0x330 ? up+0x12/0x60 xfs_dir2_grow_inode+0x62/0x110 ? xfs_trans_log_inode+0x234/0x2d0 xfs_dir2_sf_to_block+0x103/0x940 ? xfs_dir2_sf_check+0x8c/0x210 ? xfs_da_compname+0x19/0x30 ? xfs_dir2_sf_lookup+0xd0/0x3d0 xfs_dir2_sf_addname+0x10d/0x910 xfs_dir_createname+0x1ad/0x210 xfs_create+0x404/0x620 xfs_generic_create+0x24c/0x320 path_openat+0xda6/0x1030 do_filp_open+0x88/0x130 ? kmem_cache_alloc+0x50/0x210 ? __cond_resched+0x16/0x40 ? kmem_cache_alloc+0x50/0x210 do_sys_openat2+0x97/0x150 __x64_sys_creat+0x49/0x70 do_syscall_64+0x33/0x40 entry_SYSCALL_64_after_hwframe+0x44/0xae This occurs because xfs_bmap_exact_minlen_extent_alloc() initializes xfs_alloc_arg->total to xfs_bmalloca->minlen. In the context of xfs_bmap_exact_minlen_extent_alloc(), xfs_bmalloca->minlen has a value of 1 and hence the space allocator could choose an AG which has less than xfs_bmalloca->total number of free blocks available. As the transaction proceeds, one of the future space allocation requests could fail due to non-availability of free blocks in the AG that was originally chosen. This commit fixes the bug by assigning xfs_alloc_arg->total to the value of xfs_bmalloca->total. Fixes: 301519674699 ("xfs: Introduce error injection to allocate only minlen size extents for files") Signed-off-by: Chandan Babu R Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_bmap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index e0905ad171f0..585f7e795023 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -3586,7 +3586,8 @@ xfs_bmap_exact_minlen_extent_alloc( args.fsbno = ap->blkno; args.oinfo = XFS_RMAP_OINFO_SKIP_UPDATE; args.type = XFS_ALLOCTYPE_FIRST_AG; - args.total = args.minlen = args.maxlen = ap->minlen; + args.minlen = args.maxlen = ap->minlen; + args.total = ap->total; args.alignment = 1; args.minalignslop = 0; From patchwork Thu Mar 25 14:03:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandan Babu R X-Patchwork-Id: 12164163 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 041F1C433C1 for ; Thu, 25 Mar 2021 14:04:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D20F861864 for ; Thu, 25 Mar 2021 14:04:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231284AbhCYOEM (ORCPT ); Thu, 25 Mar 2021 10:04:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231332AbhCYOEB (ORCPT ); Thu, 25 Mar 2021 10:04:01 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9EB2C06175F for ; Thu, 25 Mar 2021 07:04:00 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id x126so2137706pfc.13 for ; Thu, 25 Mar 2021 07:04:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/90JFOT/tJrDN3Hm6IMek5HUiq5mXsliH81wrzAl6po=; b=he0imXOiXJz/2m5XyxTheR9Uaq201JUZMwfJfU11iWiKkO09ml7ljlQOjcOwqUOCu8 6W33UOiNen9T89vlUZ2U2rQIFTHPvWF53dB8jfxNu17c7oRamv07fsAn2fWwst/klFtp pY9tVtHbULNkOiDMwSuDiAgwnRGVF490JmjK8TilKlv6TwGJme6ukB9vveumixmufDgi GgWQpjNNx3PKQU4er5CwOW83PMnclzjE+Pq8HabQzhaTvTDAgIoqqo/CrH1z2ZADx4zf tIs6z6rzkA/tODZ6hWgHQn19lsbRhaButc7m+Sv/oRGIoX7pqrvM0Xpt1layOEWXVswN 8U8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/90JFOT/tJrDN3Hm6IMek5HUiq5mXsliH81wrzAl6po=; b=HKbUYfeJ7OScODuQsUJL7JWn8vnej3xTmwK5WPDGMT5I33cy43pcQuEKZbfKhhfPc0 a4pN4aUWs7/OR2t/adcHLEZqRBY5G4wVByJkKOAY8LYCN3qpr4G9GdByLW2gGA1HV9pw oc/mFhMiD1bc6JgqH3MzUekk7lB0OM52/rlMDqpJixJRAUo757nLBFLEVv8ZKZBP1HEX TLLHc1+n/cbmUec5UwJf5aUcCrxx5CAKlWKqDsvWegWn7lyCoJCVSZaMdKaNVxb/SJbb YAum5k5AVxUVmIyb0y5Jhged10qSdiq/yz1QFu5reg+eH7cvalMkcD77dL/Qs2HUpzxB vQfw== X-Gm-Message-State: AOAM5318VlUBDLHv8azS4ON7r0nfOySdaPNkYNH8WZrKHrUlmobSuuMk 7PAKUM0+f0VXw39GJluP1ajsyqMd8Eo= X-Google-Smtp-Source: ABdhPJwA5IntyGOoaxwROtLR3UvQt1kTmkpOK2MZLm/pOw6ACHSo4O2OHsROqqAv0O7U189rHM02aw== X-Received: by 2002:a17:902:8482:b029:e6:325b:5542 with SMTP id c2-20020a1709028482b02900e6325b5542mr10150478plo.70.1616681040283; Thu, 25 Mar 2021 07:04:00 -0700 (PDT) Received: from localhost.localdomain ([122.171.175.121]) by smtp.gmail.com with ESMTPSA id x2sm5876379pgb.89.2021.03.25.07.03.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Mar 2021 07:04:00 -0700 (PDT) From: Chandan Babu R To: linux-xfs@vger.kernel.org Cc: Chandan Babu R , djwong@kernel.org Subject: [PATCH 2/2] xfs: Fix dax inode extent calculation when direct write is performed on an unwritten extent Date: Thu, 25 Mar 2021 19:33:39 +0530 Message-Id: <20210325140339.6603-2-chandanrlinux@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210325140339.6603-1-chandanrlinux@gmail.com> References: <20210325140339.6603-1-chandanrlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org With dax enabled filesystems, a direct write operation into an existing unwritten extent results in xfs_iomap_write_direct() zero-ing and converting the extent into a normal extent before the actual data is copied from the userspace buffer. The inode extent count can increase by 2 if the extent range being written to maps to the middle of the existing unwritten extent range. Hence this commit uses XFS_IEXT_WRITE_UNWRITTEN_CNT as the extent count delta when such a write operation is being performed. Fixes: 727e1acd297c ("xfs: Check for extent overflow when trivally adding a new extent") Reported-by: Darrick J. Wong Signed-off-by: Chandan Babu R Reviewed-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- fs/xfs/xfs_iomap.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index e17ab7f42928..8b27c10a3d08 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -198,6 +198,7 @@ xfs_iomap_write_direct( bool force = false; int error; int bmapi_flags = XFS_BMAPI_PREALLOC; + int nr_exts = XFS_IEXT_ADD_NOSPLIT_CNT; ASSERT(count_fsb > 0); @@ -232,6 +233,7 @@ xfs_iomap_write_direct( bmapi_flags = XFS_BMAPI_CONVERT | XFS_BMAPI_ZERO; if (imap->br_state == XFS_EXT_UNWRITTEN) { force = true; + nr_exts = XFS_IEXT_WRITE_UNWRITTEN_CNT; dblocks = XFS_DIOSTRAT_SPACE_RES(mp, 0) << 1; } } @@ -241,8 +243,7 @@ xfs_iomap_write_direct( if (error) return error; - error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, - XFS_IEXT_ADD_NOSPLIT_CNT); + error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, nr_exts); if (error) goto out_trans_cancel;