From patchwork Wed Nov 12 15:54:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Dressler X-Patchwork-Id: 5290611 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A55E0C11AC for ; Wed, 12 Nov 2014 15:55:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CEF422018E for ; Wed, 12 Nov 2014 15:55:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 02E882017D for ; Wed, 12 Nov 2014 15:55:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752931AbaKLPyv (ORCPT ); Wed, 12 Nov 2014 10:54:51 -0500 Received: from mail-pd0-f175.google.com ([209.85.192.175]:36015 "EHLO mail-pd0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752628AbaKLPyu (ORCPT ); Wed, 12 Nov 2014 10:54:50 -0500 Received: by mail-pd0-f175.google.com with SMTP id y13so12522437pdi.34 for ; Wed, 12 Nov 2014 07:54:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=aYLqA6lo52SZGaE6X4VKoWX07o9PNpXkNCoCcLrdwE0=; b=YEgXZEl29VtS+nk0zBqqxSYfkG0E8hu6Rs54J4ar7UrpCEgDl6MoTXJ0wQ+Bq58cfx 6KpYXe59gJiMhYX0RcBedGh1FR+b7UTDk+ue6yx9Uyezg5Gp9TDtfWX/jJG7rbZgo4wY gx4i4WZT43cp4rDqE1NuYZX/HInKUX2rlp1uhjFYABvxufy35Gn7t2EadDxctJ+t6nfb DPRJkKIhkIrHfi/DVD+vZvnLB39KGgXBDGq7cKJ095Zj6sZ3lLus2yrRwo3DeK4Y/1KE Ktl82mPE15V4DiH9SVh++ti2jEHH4rA0w9OLGacWgvlu4gLlhneR6DveTtaSBqtC3mdK TicQ== X-Received: by 10.68.203.41 with SMTP id kn9mr47972961pbc.47.1415807690277; Wed, 12 Nov 2014 07:54:50 -0800 (PST) Received: from localhost.localdomain (g192.61-205-219.ppp.wakwak.ne.jp. [61.205.219.192]) by mx.google.com with ESMTPSA id o13sm22502456pby.54.2014.11.12.07.54.47 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 12 Nov 2014 07:54:49 -0800 (PST) From: Daniel Dressler To: danieru.dressler@gmail.com Cc: Chris Mason , Josef Bacik , linux-btrfs@vger.kernel.org (open list:BTRFS FILE SYSTEM), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2] Btrfs: qgroup: add BUILD_BUG to report pointer cast breakage Date: Thu, 13 Nov 2014 00:54:39 +0900 Message-Id: <1415807679-3824-1-git-send-email-danieru.dressler@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: References: Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- fs/btrfs/qgroup.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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,