[v2] Btrfs: qgroup: add BUILD_BUG to report pointer cast breakage
diff mbox

Message ID 1415807679-3824-1-git-send-email-danieru.dressler@gmail.com
State Under Review
Headers show

Commit Message

Daniel Dressler Nov. 12, 2014, 3:54 p.m. UTC
Our ulist data structure stores at max 64bit
values. qgroup has used this structure to store
pointers. In the future when we upgrade to 128bit
this casting of pointers to uint64_t will break.

This patch adds a BUILD_BUG ensuring that this
code will not be left untouched in the upgrade.

It also marks this issue on the TODO list so it
may be addressed before such an upgrade.

Signed-off-by: Daniel Dressler <danieru.dressler@gmail.com>
---
 fs/btrfs/qgroup.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

David Sterba Nov. 21, 2014, 3:46 p.m. UTC | #1
On Thu, Nov 13, 2014 at 12:54:39AM +0900, Daniel Dressler wrote:
> Our ulist data structure stores at max 64bit
> values. qgroup has used this structure to store
> pointers. In the future when we upgrade to 128bit
> this casting of pointers to uint64_t will break.

What are we going to upgrade to 128 bits?

> This patch adds a BUILD_BUG ensuring that this
> code will not be left untouched in the upgrade.
> 
> It also marks this issue on the TODO list so it
> may be addressed before such an upgrade.
> 
> +	(BUILD_BUG_ON_ZERO(sizeof(uintptr_t) > sizeof(u64)) + \

So it's pointers, this is similar to the 32bit -> 64bit transition, a
change that will affect everything, one BUILD_BUG on does not make any
difference.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index 48b60db..a9a4cab 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -44,6 +44,7 @@ 
  *  - caches fuer ulists
  *  - performance benchmarks
  *  - check all ioctl parameters
+ *  - do not cast uintptr_t to uint64_t in ulist usage
  */
 
 /*
@@ -99,8 +100,12 @@  struct btrfs_qgroup_list {
 	struct btrfs_qgroup *member;
 };
 
-#define ptr_to_u64(x) ((u64)(uintptr_t)x)
-#define u64_to_ptr(x) ((struct btrfs_qgroup *)(uintptr_t)x)
+#define ptr_to_u64(x) \
+	(BUILD_BUG_ON_ZERO(sizeof(uintptr_t) > sizeof(u64)) + \
+	((u64)(uintptr_t)x))
+#define u64_to_ptr(x) \
+	(BUILD_BUG_ON_ZERO(sizeof(uintptr_t) > sizeof(u64)) + \
+	((struct btrfs_qgroup *)(uintptr_t)x))
 
 static int
 qgroup_rescan_init(struct btrfs_fs_info *fs_info, u64 progress_objectid,