Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp388350pxj; Thu, 20 May 2021 11:38:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxDR84rxHa5yK1dWIeYusVOiCxitse5PZGD2AxNNIbCdF6YQSs8PZRVcsB5HU925fvnKVx2 X-Received: by 2002:a05:6602:54:: with SMTP id z20mr6613986ioz.48.1621535883848; Thu, 20 May 2021 11:38:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621535883; cv=none; d=google.com; s=arc-20160816; b=s9Bu653sE1nTX68ghDRacvstrdYBbSnlR9BSNwmjN+Fg73XopSSYDGcVLolrPU62WT c0pzGOLRFeGhbkS8VKTGiC9VhmiqlsmpLiivCEwv4v7BCPgd50J9ErlJRaIXO2zY0LAj vsj3kT0ux9PYk+apIwOiGScn03oxHxRQgyTEm1aNNdemRsJ4SIlgxFtqbFWJWUKra72g eUMuO9Tn0io6rc5rexWf17CqvC4AjM+cYuGDhd9vD+Uvoi+7IXiM3xj3LsYubCu3v1Sb q1uDdr2jWubpsRw+1FBgvwiH/0X8SD/qwLmGWunC8/b0fL+FwyIlw03mdrUIOSRMiJPS XGqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=tJYiSXLUnnne5UNRVuvxly2dOc/Q9g0EAZ7HCa65tNE=; b=RtEnvRQhlBs/Snas/eeEEbrsjA/UeeRPUDCiK5ebGyWifftO4Rw8s3s1QeK0o2mo3Y x5mj7Elefs2tj4tjn5lc9tuFidHY81amzDMtaDXUqjuO8SxvURCBnNfncS4bjDYVnKxH Ih6q5y39A1VrQVdkL4vUSkZcrgKGLaiGRzdkENLo586nF9Gs34CSN/WjfRbeTcJ4vwWp JZqnR4Yj881y38YB26RZkpzNjq/Ci1dHZpZbR0j28l8KqNusk10F2Z1Uvw1P5XeeOmF1 jrIvpnv/mow0kf9I+cKFhx3mKzAeicUoGUCMGgTy2s1nzvnvuUC98JqArWMKEy31+GLE P9RA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="U8/wfNRK"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c15si2949537jag.124.2021.05.20.11.37.50; Thu, 20 May 2021 11:38:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="U8/wfNRK"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235432AbhETKZF (ORCPT + 99 others); Thu, 20 May 2021 06:25:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:47658 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236154AbhETKO2 (ORCPT ); Thu, 20 May 2021 06:14:28 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 81AC661969; Thu, 20 May 2021 09:44:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503883; bh=ilqyrJZLWX5vtcWYSj8gZZF9qtB2CvUPCXl+ANBzMw4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U8/wfNRKbybV/fmgVzyc/h8jS0zkwwN3tvXHDpJ2pR5hQTY4APoBciEiJSwez4cVo QwpZ1QUmJupRkGjuJX/JC2bek4aZ74WinvcvJlM49nrzLFgXpSu3ZfwrOrKm9Ph3xe 28dbEAfH98tarmI0v0zcjiQb6m2VTZh50opf8zjg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jan Stancek , Christoph Hellwig , Dave Chinner , "Darrick J. Wong" , "Matthew Wilcox (Oracle)" Subject: [PATCH 4.19 422/425] iomap: fix sub-page uptodate handling Date: Thu, 20 May 2021 11:23:11 +0200 Message-Id: <20210520092145.266430111@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092131.308959589@linuxfoundation.org> References: <20210520092131.308959589@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christoph Hellwig commit 1cea335d1db1ce6ab71b3d2f94a807112b738a0f upstream. bio completions can race when a page spans more than one file system block. Add a spinlock to synchronize marking the page uptodate. Fixes: 9dc55f1389f9 ("iomap: add support for sub-pagesize buffered I/O without buffer heads") Reported-by: Jan Stancek Signed-off-by: Christoph Hellwig Reviewed-by: Dave Chinner Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Greg Kroah-Hartman --- fs/iomap.c | 34 ++++++++++++++++++++++++---------- include/linux/iomap.h | 1 + 2 files changed, 25 insertions(+), 10 deletions(-) --- a/fs/iomap.c +++ b/fs/iomap.c @@ -116,6 +116,7 @@ iomap_page_create(struct inode *inode, s iop = kmalloc(sizeof(*iop), GFP_NOFS | __GFP_NOFAIL); atomic_set(&iop->read_count, 0); atomic_set(&iop->write_count, 0); + spin_lock_init(&iop->uptodate_lock); bitmap_zero(iop->uptodate, PAGE_SIZE / SECTOR_SIZE); /* @@ -204,25 +205,38 @@ iomap_adjust_read_range(struct inode *in } static void -iomap_set_range_uptodate(struct page *page, unsigned off, unsigned len) +iomap_iop_set_range_uptodate(struct page *page, unsigned off, unsigned len) { struct iomap_page *iop = to_iomap_page(page); struct inode *inode = page->mapping->host; unsigned first = off >> inode->i_blkbits; unsigned last = (off + len - 1) >> inode->i_blkbits; - unsigned int i; bool uptodate = true; + unsigned long flags; + unsigned int i; - if (iop) { - for (i = 0; i < PAGE_SIZE / i_blocksize(inode); i++) { - if (i >= first && i <= last) - set_bit(i, iop->uptodate); - else if (!test_bit(i, iop->uptodate)) - uptodate = false; - } + spin_lock_irqsave(&iop->uptodate_lock, flags); + for (i = 0; i < PAGE_SIZE / i_blocksize(inode); i++) { + if (i >= first && i <= last) + set_bit(i, iop->uptodate); + else if (!test_bit(i, iop->uptodate)) + uptodate = false; } - if (uptodate && !PageError(page)) + if (uptodate) + SetPageUptodate(page); + spin_unlock_irqrestore(&iop->uptodate_lock, flags); +} + +static void +iomap_set_range_uptodate(struct page *page, unsigned off, unsigned len) +{ + if (PageError(page)) + return; + + if (page_has_private(page)) + iomap_iop_set_range_uptodate(page, off, len); + else SetPageUptodate(page); } --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -108,6 +108,7 @@ struct iomap_ops { struct iomap_page { atomic_t read_count; atomic_t write_count; + spinlock_t uptodate_lock; DECLARE_BITMAP(uptodate, PAGE_SIZE / 512); };