Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3526426pxf; Mon, 15 Mar 2021 11:31:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwpQg2+VIUCh8tO8sAMCwPnMv6rQa4hkCRJbpVHIeZHCfRDcwrAahtaJ5dfoasvjuC5kmHi X-Received: by 2002:a17:906:4117:: with SMTP id j23mr25797873ejk.10.1615833077698; Mon, 15 Mar 2021 11:31:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615833077; cv=none; d=google.com; s=arc-20160816; b=NoqfXA6Z5jSMFzn+FjhndUfod8TyCsYFYQM6/JNHHNz5W4xXGK9bh8GBdwmclcxP2/ yY5ChEjA+XZMvAK3VXEbSRQRRlq5MlWAf5Gm/eTaiBO1R5hClzRmMxzKEM/voqIjNzXB geXZSAX9Ko0Q8TfCmWUTsZMQ58yvxmwuNnBaJ5G75KQD3rEAlimI0ntOpMYHPD2HO8A1 87ozBUSAoM9YvfLvnSbb2M3TslCK0tKlctXAdtAlk9J1tEYjVstQT+2qOX+U6X8rtIRa SHeUlc3PggAstVsuOx6Swr77IVo3SGkM9h7X9NON5naNAUCFgOdW8SSJzM2q7N5c+2pI QPZw== 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=whNbblBzJeP0oUoGqfYEciAuRHBGcY2aglROiObK0dQ=; b=yrmcETlilwBDosPxi/PA2QJo+f81HXZ50pGj0D3C0qU/fyFET3bNUhtrNi3ye6alt5 IoL+O3vS1P+qQC0voX/rkOJi9OWI/aSoMAu2rdQO5iFOlouMF02v4Ahr039XXRf5SVOi ptuWpXgf+vwzPZIj+vFMGxNJ8yxu8i5cGrppKY6mbjM4rFVNV9UEo5e+thZBSpwjv//P WxYNKGlIVIS2We8msht0Qh0cluA0i4j4zw3+coYUCVdHznLJDhBA+UqLR/H2hK2B5vue 5ZbAaYA8C8d+sBGXViF1hctRRNljOToqbpFEVmkXXkjONxR1+JW8nwuJHAtp5AF2gGO2 JhLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0hAHvru8; 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 z7si10895962edc.356.2021.03.15.11.30.55; Mon, 15 Mar 2021 11:31:17 -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=0hAHvru8; 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 S236145AbhCOOei (ORCPT + 99 others); Mon, 15 Mar 2021 10:34:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:37612 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233420AbhCOOBk (ORCPT ); Mon, 15 Mar 2021 10:01:40 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 440BA64EFC; Mon, 15 Mar 2021 14:01:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816876; bh=b/wjv+TaXy3JctKRELBAG1GtOJTlYgRS9cSqdaiFkdY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0hAHvru8fAnnq++m+nn5SsfoOubAkqhyg6Mfzbzu4BvrlqDeELgazWKitNGZc6Wpz IzAUNBlHPgoxKMxH0n5wrSKl7WTg9B9ImQI3/WOqVv8Z4Bqa26pCd8B7c4iORyz08J veBN+s53+70oAVpI7oZ7zL2IFIdKMIMSKEZOZwmk= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shinichiro Kawasaki , Christoph Hellwig , Johannes Thumshirn , Jens Axboe Subject: [PATCH 5.11 178/306] block: Discard page cache of zone reset target range Date: Mon, 15 Mar 2021 14:54:01 +0100 Message-Id: <20210315135513.632459126@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135507.611436477@linuxfoundation.org> References: <20210315135507.611436477@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: Greg Kroah-Hartman From: Shin'ichiro Kawasaki commit e5113505904ea1c1c0e1f92c1cfa91fbf4da1694 upstream. When zone reset ioctl and data read race for a same zone on zoned block devices, the data read leaves stale page cache even though the zone reset ioctl zero clears all the zone data on the device. To avoid non-zero data read from the stale page cache after zone reset, discard page cache of reset target zones in blkdev_zone_mgmt_ioctl(). Introduce the helper function blkdev_truncate_zone_range() to discard the page cache. Ensure the page cache discarded by calling the helper function before and after zone reset in same manner as fallocate does. This patch can be applied back to the stable kernel version v5.10.y. Rework is needed for older stable kernels. Signed-off-by: Shin'ichiro Kawasaki Fixes: 3ed05a987e0f ("blk-zoned: implement ioctls") Cc: # 5.10+ Reviewed-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn Link: https://lore.kernel.org/r/20210311072546.678999-1-shinichiro.kawasaki@wdc.com Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- block/blk-zoned.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -318,6 +318,22 @@ int blkdev_report_zones_ioctl(struct blo return 0; } +static int blkdev_truncate_zone_range(struct block_device *bdev, fmode_t mode, + const struct blk_zone_range *zrange) +{ + loff_t start, end; + + if (zrange->sector + zrange->nr_sectors <= zrange->sector || + zrange->sector + zrange->nr_sectors > get_capacity(bdev->bd_disk)) + /* Out of range */ + return -EINVAL; + + start = zrange->sector << SECTOR_SHIFT; + end = ((zrange->sector + zrange->nr_sectors) << SECTOR_SHIFT) - 1; + + return truncate_bdev_range(bdev, mode, start, end); +} + /* * BLKRESETZONE, BLKOPENZONE, BLKCLOSEZONE and BLKFINISHZONE ioctl processing. * Called from blkdev_ioctl. @@ -329,6 +345,7 @@ int blkdev_zone_mgmt_ioctl(struct block_ struct request_queue *q; struct blk_zone_range zrange; enum req_opf op; + int ret; if (!argp) return -EINVAL; @@ -352,6 +369,11 @@ int blkdev_zone_mgmt_ioctl(struct block_ switch (cmd) { case BLKRESETZONE: op = REQ_OP_ZONE_RESET; + + /* Invalidate the page cache, including dirty pages. */ + ret = blkdev_truncate_zone_range(bdev, mode, &zrange); + if (ret) + return ret; break; case BLKOPENZONE: op = REQ_OP_ZONE_OPEN; @@ -366,8 +388,20 @@ int blkdev_zone_mgmt_ioctl(struct block_ return -ENOTTY; } - return blkdev_zone_mgmt(bdev, op, zrange.sector, zrange.nr_sectors, - GFP_KERNEL); + ret = blkdev_zone_mgmt(bdev, op, zrange.sector, zrange.nr_sectors, + GFP_KERNEL); + + /* + * Invalidate the page cache again for zone reset: writes can only be + * direct for zoned devices so concurrent writes would not add any page + * to the page cache after/during reset. The page cache may be filled + * again due to concurrent reads though and dropping the pages for + * these is fine. + */ + if (!ret && cmd == BLKRESETZONE) + ret = blkdev_truncate_zone_range(bdev, mode, &zrange); + + return ret; } static inline unsigned long *blk_alloc_zone_bitmap(int node,