From patchwork Tue Jan 7 19:25:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianlin Li X-Patchwork-Id: 11321659 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 09DFA6C1 for ; Tue, 7 Jan 2020 19:26:22 +0000 (UTC) Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.kernel.org (Postfix) with SMTP id 656C0208C4 for ; Tue, 7 Jan 2020 19:26:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=digitalocean.com header.i=@digitalocean.com header.b="RBjyUZwp" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 656C0208C4 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=digitalocean.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kernel-hardening-return-17546-patchwork-kernel-hardening=patchwork.kernel.org@lists.openwall.com Received: (qmail 9510 invoked by uid 550); 7 Jan 2020 19:26:17 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 9404 invoked from network); 7 Jan 2020 19:26:16 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=digitalocean.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tQjRs3gNjU2oRCRkkGnPvWhg7epwoT3OSGkU89AkxDQ=; b=RBjyUZwp3oCaYSH4lBnXhf98sJuriMFFB8O7XKfK7ldWb6ngmv2f9qtFr6pCkkxgGw 7CXrDYukjNwKP67z0Lw1byh8GcFRee92q4Li3sqQ/YUX/yWYSTzzPS0CWi7nplUTz0tb Jc7R/IvQnQExyScOkuyYIt2H8ViWXed3K25ks= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=tQjRs3gNjU2oRCRkkGnPvWhg7epwoT3OSGkU89AkxDQ=; b=ZLNH7CFZt9yInByc4xx+KHN2aT0YXF6OZJ6dnFicb9pkq1UZViM1XbevZ7MSHr3o4m WUa+eMZLhrE5wcxdOXVeBq9uirqjeb6sViV8ODewtUy6w6LPTkM0wntauUBPnUFGI+3A zJX1PqA6AMcI3QcpuTpHBUXvPrY9yqwpDieAfVkt5M/K3NDXi0x1UEUHxWm9eXdaCVe2 XZGbt1q4EMQ+HrOQeZqfyYLYXwcW5DEfJQFGqhVa+Z1pa1Eh9nhcBPyeMZGIzmVwjV6d eQb81WDOXhO6L89Z3WduKapJDPHjL9XzskCHb32/V2HPT6uXcdtqeSCD0wso1PY5PLan iJdA== X-Gm-Message-State: APjAAAWBXX+D+b8aQAiZ5L4AOxkA6mVAiDNSScZc/UJNNe9wLC0rZzPS bH68iDz2YESy8vHFOnSfqODO X-Google-Smtp-Source: APXvYqxUxZ+QGpsSnWO2wfDZLiBGzqQSyJZLkZZl9iPaevdfkH2M+Sp/oQ3CIezE7wg13+qNsbCYpQ== X-Received: by 2002:a81:9c14:: with SMTP id m20mr702845ywa.143.1578425164670; Tue, 07 Jan 2020 11:26:04 -0800 (PST) From: Tianlin Li To: kernel-hardening@lists.openwall.com, keescook@chromium.org Cc: Alex Deucher , christian.koenig@amd.com, David1.Zhou@amd.com, David Airlie , Daniel Vetter , amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Tianlin Li Subject: [PATCH 1/2] drm/radeon: have the callers of set_memory_*() check the return value Date: Tue, 7 Jan 2020 13:25:54 -0600 Message-Id: <20200107192555.20606-2-tli@digitalocean.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200107192555.20606-1-tli@digitalocean.com> References: <20200107192555.20606-1-tli@digitalocean.com> Have the callers of set_memory_*() in drm/radeon check the return value. Change the return type of the callers properly. Signed-off-by: Tianlin Li --- drivers/gpu/drm/radeon/radeon.h | 2 +- drivers/gpu/drm/radeon/radeon_gart.c | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h index 30e32adc1fc6..a23e58397293 100644 --- a/drivers/gpu/drm/radeon/radeon.h +++ b/drivers/gpu/drm/radeon/radeon.h @@ -661,7 +661,7 @@ struct radeon_gart { }; int radeon_gart_table_ram_alloc(struct radeon_device *rdev); -void radeon_gart_table_ram_free(struct radeon_device *rdev); +int radeon_gart_table_ram_free(struct radeon_device *rdev); int radeon_gart_table_vram_alloc(struct radeon_device *rdev); void radeon_gart_table_vram_free(struct radeon_device *rdev); int radeon_gart_table_vram_pin(struct radeon_device *rdev); diff --git a/drivers/gpu/drm/radeon/radeon_gart.c b/drivers/gpu/drm/radeon/radeon_gart.c index d4d3778d0a98..59039ab602e8 100644 --- a/drivers/gpu/drm/radeon/radeon_gart.c +++ b/drivers/gpu/drm/radeon/radeon_gart.c @@ -71,6 +71,7 @@ int radeon_gart_table_ram_alloc(struct radeon_device *rdev) { void *ptr; + int ret; ptr = pci_alloc_consistent(rdev->pdev, rdev->gart.table_size, &rdev->gart.table_addr); @@ -80,8 +81,16 @@ int radeon_gart_table_ram_alloc(struct radeon_device *rdev) #ifdef CONFIG_X86 if (rdev->family == CHIP_RS400 || rdev->family == CHIP_RS480 || rdev->family == CHIP_RS690 || rdev->family == CHIP_RS740) { - set_memory_uc((unsigned long)ptr, + ret = set_memory_uc((unsigned long)ptr, rdev->gart.table_size >> PAGE_SHIFT); + if (ret) { + pci_free_consistent(rdev->pdev, rdev->gart.table_size, + (void *)rdev->gart.ptr, + rdev->gart.table_addr); + rdev->gart.ptr = NULL; + rdev->gart.table_addr = 0; + return ret; + } } #endif rdev->gart.ptr = ptr; @@ -98,16 +107,20 @@ int radeon_gart_table_ram_alloc(struct radeon_device *rdev) * (r1xx-r3xx, non-pcie r4xx, rs400). These asics require the * gart table to be in system memory. */ -void radeon_gart_table_ram_free(struct radeon_device *rdev) +int radeon_gart_table_ram_free(struct radeon_device *rdev) { + int ret; + if (rdev->gart.ptr == NULL) { - return; + return 0; } #ifdef CONFIG_X86 if (rdev->family == CHIP_RS400 || rdev->family == CHIP_RS480 || rdev->family == CHIP_RS690 || rdev->family == CHIP_RS740) { - set_memory_wb((unsigned long)rdev->gart.ptr, + ret = set_memory_wb((unsigned long)rdev->gart.ptr, rdev->gart.table_size >> PAGE_SHIFT); + if (ret) + return ret; } #endif pci_free_consistent(rdev->pdev, rdev->gart.table_size, @@ -115,6 +128,7 @@ void radeon_gart_table_ram_free(struct radeon_device *rdev) rdev->gart.table_addr); rdev->gart.ptr = NULL; rdev->gart.table_addr = 0; + return 0; } /** From patchwork Tue Jan 7 19:25:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianlin Li X-Patchwork-Id: 11321661 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B1F8A6C1 for ; Tue, 7 Jan 2020 19:26:28 +0000 (UTC) Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.kernel.org (Postfix) with SMTP id 1A3A0208C4 for ; Tue, 7 Jan 2020 19:26:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=digitalocean.com header.i=@digitalocean.com header.b="a3skjP/A" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1A3A0208C4 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=digitalocean.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kernel-hardening-return-17547-patchwork-kernel-hardening=patchwork.kernel.org@lists.openwall.com Received: (qmail 9701 invoked by uid 550); 7 Jan 2020 19:26:19 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 9589 invoked from network); 7 Jan 2020 19:26:18 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=digitalocean.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=maOi+ccdSCJ33tytaZ2VQyWTlm9roQsB2CYyKUcC3tE=; b=a3skjP/AmaWwBHZeZWluAghlXwxiT7Cj7kdIwSY35YoouSaTAle6gkkF+gWSQ43i5K B0GbiFcbbFVZraT3GERgOABL8Uc68kYFZIreZ/RiZRxaBPKz51UcdeY8c9TkW4rBxplO +ma4KhzsrQj/BcgUSva7gsUmK8tJO0k2NfeH0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=maOi+ccdSCJ33tytaZ2VQyWTlm9roQsB2CYyKUcC3tE=; b=GvQAqfIMoRjdHpc5t6xypsNU1LKjBgy/avzLEK7WrTZCt5k0kUYO3X+htIWOOKQ2Zj jsN4iQ3Wsd5yESOuaS7+VUoH6lB3P2XQ5DoI81o7zEe1tzpfHga6A7Hfbx3cHEgBigrP l2K7WF82/Q79YS3EpHYZeQkvHuaIXbyb1qtEYgr7Jj5mq5+H04QoBmvQ/aehQpDUUiOK r1gAunCrGLXwz7Q1dtSewhjhrxN4+CbknHAa+NjO5Q14+ogAPzFp4JwkG70lBBZLlEv4 uOiSgEs8HEjqYz5lNNlp+4+B2E22l6CFzcdV8tiA1DGDPOSI2yDOHyB8vSgMSCniXRYx OEGQ== X-Gm-Message-State: APjAAAV1zcw2d3S20CCZ3c5etG//9zoTpC463DltWwknPPK7qIvBqKAZ U/kEKRCS3fqeUlmhswbRumGe X-Google-Smtp-Source: APXvYqwCwkS16hDGTInMHpIbsWfaGLyz0bdtQUZqjjL2wAm7ADS3K2eO1OR9tckNRyznHTSO/nu0Yg== X-Received: by 2002:a81:ec01:: with SMTP id j1mr738569ywm.274.1578425166700; Tue, 07 Jan 2020 11:26:06 -0800 (PST) From: Tianlin Li To: kernel-hardening@lists.openwall.com, keescook@chromium.org Cc: Alex Deucher , christian.koenig@amd.com, David1.Zhou@amd.com, David Airlie , Daniel Vetter , amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Tianlin Li Subject: [PATCH 2/2] drm/radeon: change call sites to handle return value properly. Date: Tue, 7 Jan 2020 13:25:55 -0600 Message-Id: <20200107192555.20606-3-tli@digitalocean.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200107192555.20606-1-tli@digitalocean.com> References: <20200107192555.20606-1-tli@digitalocean.com> Ideally, the failure of set_memory_*() should be passed up the call stack, and callers should examine the failure and deal with it. Fix those call sites in drm/radeon to handle retval properly. Since fini functions are always void, print errors for the failures. Signed-off-by: Tianlin Li --- drivers/gpu/drm/radeon/r100.c | 3 ++- drivers/gpu/drm/radeon/rs400.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/radeon/r100.c b/drivers/gpu/drm/radeon/r100.c index 110fb38004b1..7eafe15ba124 100644 --- a/drivers/gpu/drm/radeon/r100.c +++ b/drivers/gpu/drm/radeon/r100.c @@ -706,7 +706,8 @@ void r100_pci_gart_fini(struct radeon_device *rdev) { radeon_gart_fini(rdev); r100_pci_gart_disable(rdev); - radeon_gart_table_ram_free(rdev); + if (radeon_gart_table_ram_free(rdev)) + DRM_ERROR("radeon: failed free system ram for GART page table.\n"); } int r100_irq_set(struct radeon_device *rdev) diff --git a/drivers/gpu/drm/radeon/rs400.c b/drivers/gpu/drm/radeon/rs400.c index 117f60af1ee4..de3674f5fe23 100644 --- a/drivers/gpu/drm/radeon/rs400.c +++ b/drivers/gpu/drm/radeon/rs400.c @@ -210,7 +210,8 @@ void rs400_gart_fini(struct radeon_device *rdev) { radeon_gart_fini(rdev); rs400_gart_disable(rdev); - radeon_gart_table_ram_free(rdev); + if (radeon_gart_table_ram_free(rdev)) + DRM_ERROR("radeon: failed free system ram for GART page table.\n"); } #define RS400_PTE_UNSNOOPED (1 << 0)