Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1270045pxa; Thu, 20 Aug 2020 07:11:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzRc6cGMk0eeHZVxiV2HZIo5JGp/59jOIoXqOiZm+DbH4UYN/aLvIL584niULrz0luZOPvZ X-Received: by 2002:a05:6402:206a:: with SMTP id bd10mr2976345edb.321.1597932705969; Thu, 20 Aug 2020 07:11:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597932705; cv=none; d=google.com; s=arc-20160816; b=R+JbqewoChuXVzmYTu+wC7JHM4QqyVWORcOz8aCd/YZgVPnZd07eT2Mvsh3iBAW5Uz cYRw3yxWiEjrC+5MDjjhyK4DFUoi6hCa1hAkhkPCNGBjnkNj8DfWawQcto1WS1UCnDpQ N6uDGbRckzdhndQTsreiASjzB192+toz4fatNcbbcbe4VSYIEjO5VkQ8KnIL/LPdBboZ 5c+rolA1O2RNot63HNKxgnO+aSRq9xJ5slHJ6ijpklAhv8YY4xEVVaiRDi+bxmyVnhcw K2bRgmpRgza2xwuBqWytgoRSyNAMNgMWVvzfWsLYBgM8b0Ofy4Qnf7LAK7Jo66jTM2vj RVoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=suUiIPjAKMaTppeEMQZqIrl2Ymna0ZsUkUj1yy9GESM=; b=rm7Xe5gNeTqxpyqeLMzhqvqTgr/bFiXG/hjCtEmri8D48oTOqgrTlKFB+FZR0aItve oi4P8GnBLL1ezIuE1ynVmm9VjeqXKAab7OblPi+Yz+zEzhZpMwe094aFwR25Reqfvq3J 5AerxYxnouF/icQnTwMaKvLBEgGZe3s0Nc+gl9lxAsRWJfifNs+esHav6dsvHQ24RcmL G9Gibuigeb3rX7+8m1GDlmDm2vFV/qQJ0eH9S98k0w/vrb1Zy6tGXlK/up/7FJlHelDf OZNlCwuDun0lB+VntJO+12hCS7z5ex4VYOUAQGUsSumxlsmCTgPJZ/P8xJCBs3tZhptl pSFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=glUCWX8M; 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=fail (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 cq22si1327115edb.609.2020.08.20.07.11.21; Thu, 20 Aug 2020 07:11:45 -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=@kernel.org header.s=default header.b=glUCWX8M; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731170AbgHTN6T (ORCPT + 99 others); Thu, 20 Aug 2020 09:58:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:60006 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726959AbgHTJY1 (ORCPT ); Thu, 20 Aug 2020 05:24:27 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DD51922CB2; Thu, 20 Aug 2020 09:24:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597915467; bh=Cm2feadPvPt9PmnUf0EuHHArp78fgf63sITjvIEfr3E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=glUCWX8MrLfx1p0Uz2090itJcZtYlZMExJtpV65J6B0pxKAbdFaPWDvdsxwcOUF+g wrL/W7At2Xk4+6ZGqeubsRTpp2y68NCN3nV79+8G+Uuci9vUa4CssliUUiKN2itPuP EjPESar8+HEEKXFn3/vdJgU28EUMbFTt3ld+O4N4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Johannes Thumshirn , David Sterba Subject: [PATCH 5.8 023/232] btrfs: pass checksum type via BTRFS_IOC_FS_INFO ioctl Date: Thu, 20 Aug 2020 11:17:54 +0200 Message-Id: <20200820091613.872804938@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091612.692383444@linuxfoundation.org> References: <20200820091612.692383444@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Johannes Thumshirn commit 137c541821a83debb63b3fa8abdd1cbc41bdf3a1 upstream. With the recent addition of filesystem checksum types other than CRC32c, it is not anymore hard-coded which checksum type a btrfs filesystem uses. Up to now there is no good way to read the filesystem checksum, apart from reading the filesystem UUID and then query sysfs for the checksum type. Add a new csum_type and csum_size fields to the BTRFS_IOC_FS_INFO ioctl command which usually is used to query filesystem features. Also add a flags member indicating that the kernel responded with a set csum_type and csum_size field. For compatibility reasons, only return the csum_type and csum_size if the BTRFS_FS_INFO_FLAG_CSUM_INFO flag was passed to the kernel. Also clear any unknown flags so we don't pass false positives to user-space newer than the kernel. To simplify further additions to the ioctl, also switch the padding to a u8 array. Pahole was used to verify the result of this switch: The csum members are added before flags, which might look odd, but this is to keep the alignment requirements and not to introduce holes in the structure. $ pahole -C btrfs_ioctl_fs_info_args fs/btrfs/btrfs.ko struct btrfs_ioctl_fs_info_args { __u64 max_id; /* 0 8 */ __u64 num_devices; /* 8 8 */ __u8 fsid[16]; /* 16 16 */ __u32 nodesize; /* 32 4 */ __u32 sectorsize; /* 36 4 */ __u32 clone_alignment; /* 40 4 */ __u16 csum_type; /* 44 2 */ __u16 csum_size; /* 46 2 */ __u64 flags; /* 48 8 */ __u8 reserved[968]; /* 56 968 */ /* size: 1024, cachelines: 16, members: 10 */ }; Fixes: 3951e7f050ac ("btrfs: add xxhash64 to checksumming algorithms") Fixes: 3831bf0094ab ("btrfs: add sha256 to checksumming algorithm") CC: stable@vger.kernel.org # 5.5+ Signed-off-by: Johannes Thumshirn Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/ioctl.c | 16 +++++++++++++--- include/uapi/linux/btrfs.h | 14 ++++++++++++-- 2 files changed, 25 insertions(+), 5 deletions(-) --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -3217,11 +3217,15 @@ static long btrfs_ioctl_fs_info(struct b struct btrfs_ioctl_fs_info_args *fi_args; struct btrfs_device *device; struct btrfs_fs_devices *fs_devices = fs_info->fs_devices; + u64 flags_in; int ret = 0; - fi_args = kzalloc(sizeof(*fi_args), GFP_KERNEL); - if (!fi_args) - return -ENOMEM; + fi_args = memdup_user(arg, sizeof(*fi_args)); + if (IS_ERR(fi_args)) + return PTR_ERR(fi_args); + + flags_in = fi_args->flags; + memset(fi_args, 0, sizeof(*fi_args)); rcu_read_lock(); fi_args->num_devices = fs_devices->num_devices; @@ -3237,6 +3241,12 @@ static long btrfs_ioctl_fs_info(struct b fi_args->sectorsize = fs_info->sectorsize; fi_args->clone_alignment = fs_info->sectorsize; + if (flags_in & BTRFS_FS_INFO_FLAG_CSUM_INFO) { + fi_args->csum_type = btrfs_super_csum_type(fs_info->super_copy); + fi_args->csum_size = btrfs_super_csum_size(fs_info->super_copy); + fi_args->flags |= BTRFS_FS_INFO_FLAG_CSUM_INFO; + } + if (copy_to_user(arg, fi_args, sizeof(*fi_args))) ret = -EFAULT; --- a/include/uapi/linux/btrfs.h +++ b/include/uapi/linux/btrfs.h @@ -243,6 +243,13 @@ struct btrfs_ioctl_dev_info_args { __u8 path[BTRFS_DEVICE_PATH_NAME_MAX]; /* out */ }; +/* + * Retrieve information about the filesystem + */ + +/* Request information about checksum type and size */ +#define BTRFS_FS_INFO_FLAG_CSUM_INFO (1 << 0) + struct btrfs_ioctl_fs_info_args { __u64 max_id; /* out */ __u64 num_devices; /* out */ @@ -250,8 +257,11 @@ struct btrfs_ioctl_fs_info_args { __u32 nodesize; /* out */ __u32 sectorsize; /* out */ __u32 clone_alignment; /* out */ - __u32 reserved32; - __u64 reserved[122]; /* pad to 1k */ + /* See BTRFS_FS_INFO_FLAG_* */ + __u16 csum_type; /* out */ + __u16 csum_size; /* out */ + __u64 flags; /* in/out */ + __u8 reserved[968]; /* pad to 1k */ }; /*