From patchwork Sat Mar 19 19:56:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolai Stange X-Patchwork-Id: 8630581 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CFE7A9F36E for ; Mon, 21 Mar 2016 09:25:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C3634202AE for ; Mon, 21 Mar 2016 09:25:40 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 8CD18202DD for ; Mon, 21 Mar 2016 09:25:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 257506E26E; Mon, 21 Mar 2016 09:25:00 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com [IPv6:2a00:1450:400c:c09::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id 30B076E198 for ; Sat, 19 Mar 2016 19:56:47 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id r129so1336625wmr.2 for ; Sat, 19 Mar 2016 12:56:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=WFYhevcvnSwGc9J9bYL+wKoV8h29syZZRTB0pzcmXyA=; b=NbQjX5cBPngBi7MSZQYQ2BqLhdOsI5noeLAHBo1BgRRV1/tM/+18T3lNmnnsn1bOvp Rrd+VLp+Hm09uQmqht2oUrskTZAPLBCXfdqoIwOsl2QupMI3FEIf6iovT+zhXLLOQJ/x Z6udCvNVSiiID2uLOMcdlVO4ttHXNX5JOqYFv36cVqQTrjcPjJWjI+XwV0d5v9/W95vZ hjujH6H/1pVkZE0UQd4eEwkxbrGVtvF1CRiA0eGOb9wEn2XrxW0wn7rrmuf8BPujMTA6 CXbUMlvyiHZ9C7ZnLLwtolVB0zYFjT+yr/dYKqi1NnYVpPorVz3luCZfAWqc33UFZD8F eQQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=WFYhevcvnSwGc9J9bYL+wKoV8h29syZZRTB0pzcmXyA=; b=Fk/7oT8efM6q+rIZVOP/XoW/8M/tKgK7PSZKmx+yiKQoubXn06DgP+HRXX0a4Ek0pL pt8qWuyU5bhm/N26hcQHLj8Kt7PSRpk6xT8D7UAL8kIKASQnAUmA3f/BY29lmbJDQvwG AGd/S1h/XJWJLRM/q4hRnwDsG/ayP9TcsEJqUu80Ch/ZEeTLbdLK0icTCLOh+0M5DjG1 iTQVjijn5pb3PvPICPJgtTFmHWeoWlKumfBNcGJbb39erjI/GKv8hipVgmPwFT814JFG Erq6mBDwlVdkRt02vJ4OiCn2kOEC3ZQ0BKwTfA2DEU7njDzVa7GMlQe8FEmropSTg5ww 4TdQ== X-Gm-Message-State: AD7BkJKnVy7QJa7OjzlkhukASoHaou1WtEMArprBbmZME5RcNRln66xxxtxOTluTJMJYBA== X-Received: by 10.194.11.67 with SMTP id o3mr21936537wjb.74.1458417404823; Sat, 19 Mar 2016 12:56:44 -0700 (PDT) Received: from localhost (f054124197.adsl.alicedsl.de. [78.54.124.197]) by smtp.gmail.com with ESMTPSA id z6sm4936862wme.9.2016.03.19.12.56.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 19 Mar 2016 12:56:44 -0700 (PDT) From: Nicolai Stange To: Alex Deucher , =?UTF-8?q?Christian=20K=C3=B6nig?= , David Airlie Subject: [PATCH] drm/radeon: evergreen_hpd_init()/_fini(): fix HPD IRQ bitset Date: Sat, 19 Mar 2016 20:56:41 +0100 Message-Id: <1458417401-3756-1-git-send-email-nicstange@gmail.com> X-Mailer: git-send-email 2.7.3 X-Mailman-Approved-At: Mon, 21 Mar 2016 09:24:51 +0000 Cc: Nicolai Stange , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable 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 The values of all but the RADEON_HPD_NONE members of the radeon_hpd_id enum transform 1:1 into bit positions within the 'enabled' bitset as assembled by evergreen_hpd_init(): enabled |= 1 << radeon_connector->hpd.hpd; However, if ->hpd.hpd happens to equal RADEON_HPD_NONE == 0xff, UBSAN reports UBSAN: Undefined behaviour in drivers/gpu/drm/radeon/evergreen.c:1867:16 shift exponent 255 is too large for 32-bit type 'int' [...] Call Trace: [] dump_stack+0xbc/0x117 [] ? _atomic_dec_and_lock+0x169/0x169 [] ubsan_epilogue+0xd/0x4e [] __ubsan_handle_shift_out_of_bounds+0x1fb/0x254 [] ? atom_execute_table+0x3e/0x50 [radeon] [] ? __ubsan_handle_load_invalid_value+0x158/0x158 [] ? radeon_get_pll_use_mask+0x130/0x130 [radeon] [] ? wake_up_klogd_work_func+0x60/0x60 [] ? vprintk_default+0x3e/0x60 [] evergreen_hpd_init+0x274/0x2d0 [radeon] [] ? evergreen_hpd_init+0x274/0x2d0 [radeon] [] radeon_modeset_init+0x8ce/0x18d0 [radeon] [] radeon_driver_load_kms+0x186/0x350 [radeon] [] drm_dev_register+0xc6/0x100 [drm] [] drm_get_pci_dev+0xe4/0x490 [drm] [] ? kfree+0x220/0x370 [] radeon_pci_probe+0x112/0x140 [radeon] [...] ===================================================================== radeon 0000:01:00.0: No connectors reported connected with modes The net effect is that radeon_irq_kms_enable_hpd() enables the HPD interrupts for all HPD pins in the range from 0 to RADEON_MAX_HPD_PINS. The system seems to work without any noticeable glitches though. All of the above applies analogously to evergreen_hpd_fini(). Silence UBSAN by checking ->hpd.hpd for RADEON_HPD_NONE before oring it into the 'enabled' bitset in evergreen_hpd_init() or the 'disabled' bitset in evergreen_hpd_fini() respectively. Signed-off-by: Nicolai Stange --- Applicable to linux-next-20160318. drivers/gpu/drm/radeon/evergreen.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/radeon/evergreen.c b/drivers/gpu/drm/radeon/evergreen.c index 76c4bdf..6360717 100644 --- a/drivers/gpu/drm/radeon/evergreen.c +++ b/drivers/gpu/drm/radeon/evergreen.c @@ -1864,7 +1864,8 @@ void evergreen_hpd_init(struct radeon_device *rdev) break; } radeon_hpd_set_polarity(rdev, radeon_connector->hpd.hpd); - enabled |= 1 << radeon_connector->hpd.hpd; + if (radeon_connector->hpd.hpd != RADEON_HPD_NONE) + enabled |= 1 << radeon_connector->hpd.hpd; } radeon_irq_kms_enable_hpd(rdev, enabled); } @@ -1907,7 +1908,8 @@ void evergreen_hpd_fini(struct radeon_device *rdev) default: break; } - disabled |= 1 << radeon_connector->hpd.hpd; + if (radeon_connector->hpd.hpd != RADEON_HPD_NONE) + disabled |= 1 << radeon_connector->hpd.hpd; } radeon_irq_kms_disable_hpd(rdev, disabled); }