Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp241401pxf; Wed, 10 Mar 2021 05:28:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJznQ+kT6ks/J9DY1k2VLc2VLmKR1d9yH3w/rQg5AkY/E146t7dWF7CKZp2ZgXsQ8RJPAFU0 X-Received: by 2002:a17:906:1a16:: with SMTP id i22mr3671402ejf.522.1615382882111; Wed, 10 Mar 2021 05:28:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615382882; cv=none; d=google.com; s=arc-20160816; b=ZYnZWoezFh19xSuSYA1q1TG2Xbj8kZvvTAFRz0k5yz3P3ojr+20NO4GAZP033O1AsV ugA3gDD/7xoRpbu7+YnuFqLFpk/COhj95UlKW60VdzKRj78zrlM7g2/JPjtjD+gRVo4q IQKOKdlYRUKLEs+hIFggc1Pvg/uK0iRB3NpU1nDFAhvaE1PX+yFiQSaJ/rf/ThbhfV8c AK02j4LreOVi9CPKC8kgnAjH5XJmFhsaMjOFCjnY03G6aAoLXiSCLo/4UQUbBVhuiQJm InQVSGhR3OQ115DDD75QDpR4/op63hFMGcwxtrDqeJV98sdvkDxsGPqQMIFfTikZ4mvk 36aw== 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=rwgS0adDC5RVXZzwdojZ5MaRG+Z6R9Ljl3Oci/w2zGk=; b=uR6ZWahhZlPl1w0mTm/PGw1Z65LwghtCJMM+NC9phmL+QcWSNOMzO5nv157C+Farkh Ly8hiCD0W5tsFE6aodmA1+TVgeYY8ACF27GNQEBxNA7WGUXoPc9y/r4Le3LNqNJwOeSx +fjQXAVBn3RLFVpxd1ZNVeOLSAh3wsn7vptonNKprzwSRYXvZ3qpLUDKZr5bkOY9RNTJ Gq9RuQBA0V7sr5RTov3msuAv9AevYXxr1gc0bPQ2pMxt3FMVfhkoa2HvkcIPDjA/VJXQ GalAyQQSOEULXanhY+xqhE8m9CeJ02RhnRhmzWMzRDGuOED/st5yaOuFCClXcMvlpliI jdMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="UREr8/Sw"; 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 y17si11835906ejh.440.2021.03.10.05.27.36; Wed, 10 Mar 2021 05:28:02 -0800 (PST) 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="UREr8/Sw"; 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 S233809AbhCJN0N (ORCPT + 99 others); Wed, 10 Mar 2021 08:26:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:46158 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233006AbhCJNYq (ORCPT ); Wed, 10 Mar 2021 08:24:46 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id AB66664FDA; Wed, 10 Mar 2021 13:24:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615382685; bh=DdBcEjlaR5j3lG1ocQ8xi77KDagXpgXE9CwA15jTWV8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UREr8/SwRLlA5JQnXtUrK1PuiiVbv8WMCjSiKBaikK/EHjwu59UFBHFWV94ql7hqk w+rabGvq2J0d0y/zACxtDNLOUr9PEGti1b+p6PcCwMPM4dR0cqNwcLWyurhgLqRur5 Db/1dwFpEwKe/ABOGlLIcPewCFBRpxp9GiXSwnck= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jeffle Xu , Mike Snitzer Subject: [PATCH 5.4 03/24] dm table: fix DAX iterate_devices based device capability checks Date: Wed, 10 Mar 2021 14:24:15 +0100 Message-Id: <20210310132320.654836213@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210310132320.550932445@linuxfoundation.org> References: <20210310132320.550932445@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: Jeffle Xu commit 5b0fab508992c2e120971da658ce80027acbc405 upstream. Fix dm_table_supports_dax() and invert logic of both iterate_devices_callout_fn so that all devices' DAX capabilities are properly checked. Fixes: 545ed20e6df6 ("dm: add infrastructure for DAX support") Cc: stable@vger.kernel.org Signed-off-by: Jeffle Xu Signed-off-by: Mike Snitzer Signed-off-by: Greg Kroah-Hartman --- drivers/md/dm-table.c | 37 ++++++++++--------------------------- drivers/md/dm.c | 2 +- drivers/md/dm.h | 2 +- 3 files changed, 12 insertions(+), 29 deletions(-) --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c @@ -888,24 +888,24 @@ void dm_table_set_type(struct dm_table * EXPORT_SYMBOL_GPL(dm_table_set_type); /* validate the dax capability of the target device span */ -int device_supports_dax(struct dm_target *ti, struct dm_dev *dev, +int device_not_dax_capable(struct dm_target *ti, struct dm_dev *dev, sector_t start, sector_t len, void *data) { int blocksize = *(int *) data, id; bool rc; id = dax_read_lock(); - rc = dax_supported(dev->dax_dev, dev->bdev, blocksize, start, len); + rc = !dax_supported(dev->dax_dev, dev->bdev, blocksize, start, len); dax_read_unlock(id); return rc; } /* Check devices support synchronous DAX */ -static int device_dax_synchronous(struct dm_target *ti, struct dm_dev *dev, - sector_t start, sector_t len, void *data) +static int device_not_dax_synchronous_capable(struct dm_target *ti, struct dm_dev *dev, + sector_t start, sector_t len, void *data) { - return dev->dax_dev && dax_synchronous(dev->dax_dev); + return !dev->dax_dev || !dax_synchronous(dev->dax_dev); } bool dm_table_supports_dax(struct dm_table *t, @@ -922,7 +922,7 @@ bool dm_table_supports_dax(struct dm_tab return false; if (!ti->type->iterate_devices || - !ti->type->iterate_devices(ti, iterate_fn, blocksize)) + ti->type->iterate_devices(ti, iterate_fn, blocksize)) return false; } @@ -996,7 +996,7 @@ static int dm_table_determine_type(struc verify_bio_based: /* We must use this table as bio-based */ t->type = DM_TYPE_BIO_BASED; - if (dm_table_supports_dax(t, device_supports_dax, &page_size) || + if (dm_table_supports_dax(t, device_not_dax_capable, &page_size) || (list_empty(devices) && live_md_type == DM_TYPE_DAX_BIO_BASED)) { t->type = DM_TYPE_DAX_BIO_BASED; } else { @@ -1715,23 +1715,6 @@ static int device_dax_write_cache_enable return false; } -static int dm_table_supports_dax_write_cache(struct dm_table *t) -{ - struct dm_target *ti; - unsigned i; - - for (i = 0; i < dm_table_get_num_targets(t); i++) { - ti = dm_table_get_target(t, i); - - if (ti->type->iterate_devices && - ti->type->iterate_devices(ti, - device_dax_write_cache_enabled, NULL)) - return true; - } - - return false; -} - static int device_is_rotational(struct dm_target *ti, struct dm_dev *dev, sector_t start, sector_t len, void *data) { @@ -1918,15 +1901,15 @@ void dm_table_set_restrictions(struct dm } blk_queue_write_cache(q, wc, fua); - if (dm_table_supports_dax(t, device_supports_dax, &page_size)) { + if (dm_table_supports_dax(t, device_not_dax_capable, &page_size)) { blk_queue_flag_set(QUEUE_FLAG_DAX, q); - if (dm_table_supports_dax(t, device_dax_synchronous, NULL)) + if (dm_table_supports_dax(t, device_not_dax_synchronous_capable, NULL)) set_dax_synchronous(t->md->dax_dev); } else blk_queue_flag_clear(QUEUE_FLAG_DAX, q); - if (dm_table_supports_dax_write_cache(t)) + if (dm_table_any_dev_attr(t, device_dax_write_cache_enabled)) dax_write_cache(t->md->dax_dev, true); /* Ensure that all underlying devices are non-rotational. */ --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -1139,7 +1139,7 @@ static bool dm_dax_supported(struct dax_ if (!map) goto out; - ret = dm_table_supports_dax(map, device_supports_dax, &blocksize); + ret = dm_table_supports_dax(map, device_not_dax_capable, &blocksize); out: dm_put_live_table(md, srcu_idx); --- a/drivers/md/dm.h +++ b/drivers/md/dm.h @@ -74,7 +74,7 @@ void dm_table_free_md_mempools(struct dm struct dm_md_mempools *dm_table_get_md_mempools(struct dm_table *t); bool dm_table_supports_dax(struct dm_table *t, iterate_devices_callout_fn fn, int *blocksize); -int device_supports_dax(struct dm_target *ti, struct dm_dev *dev, +int device_not_dax_capable(struct dm_target *ti, struct dm_dev *dev, sector_t start, sector_t len, void *data); void dm_lock_md_type(struct mapped_device *md);