From patchwork Thu Feb 5 05:44:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 5781061 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 151EABF440 for ; Thu, 5 Feb 2015 05:42:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0FD6F202FF for ; Thu, 5 Feb 2015 05:42:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1026F2034B for ; Thu, 5 Feb 2015 05:42:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751721AbbBEFmZ (ORCPT ); Thu, 5 Feb 2015 00:42:25 -0500 Received: from mga01.intel.com ([192.55.52.88]:62564 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750910AbbBEFmY (ORCPT ); Thu, 5 Feb 2015 00:42:24 -0500 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP; 04 Feb 2015 21:42:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.09,522,1418112000"; d="scan'208";a="647613517" Received: from gerry-dev.bj.intel.com ([10.238.158.52]) by orsmga001.jf.intel.com with ESMTP; 04 Feb 2015 21:42:19 -0800 From: Jiang Liu To: "Rafael J. Wysocki" , Thomas Gleixner , Bjorn Helgaas , Yinghai Lu , Borislav Petkov , Lv Zheng , Len Brown Cc: Tony Luck , x86@kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-acpi@vger.kernel.org, Jiang Liu Subject: [Patch v4 03/23] ACPI: Implement proper length checks for mem resources Date: Thu, 5 Feb 2015 13:44:29 +0800 Message-Id: <1423115089-12904-4-git-send-email-jiang.liu@linux.intel.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1423115089-12904-1-git-send-email-jiang.liu@linux.intel.com> References: <1423115089-12904-1-git-send-email-jiang.liu@linux.intel.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, 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 From: Thomas Gleixner Check whether the resulting length is the same as the given length. Check for start <= end as well. We need to hand in the resource for this, so we can apply the flags directly. [Jiang] Remove enforcement that resource starting address must be non-zero. Signed-off-by: Thomas Gleixner Signed-off-by: Jiang Liu --- drivers/acpi/resource.c | 62 ++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/drivers/acpi/resource.c b/drivers/acpi/resource.c index 1c616a56e007..3e7d9f6eb875 100644 --- a/drivers/acpi/resource.c +++ b/drivers/acpi/resource.c @@ -34,21 +34,37 @@ #define valid_IRQ(i) (true) #endif -static unsigned long acpi_dev_memresource_flags(u64 len, u8 write_protect, - bool window) +static bool acpi_dev_resource_len_valid(u64 start, u64 end, u64 len, bool io) { - unsigned long flags = IORESOURCE_MEM; + u64 reslen = end - start + 1; - if (len == 0) - flags |= IORESOURCE_DISABLED; + /* + * CHECKME: len might be required to check versus a minimum + * length as well. 1 for io is fine, but for memory it does + * not make any sense at all. + */ + if (len && reslen && reslen == len && start <= end) + return true; + + pr_info("ACPI: invalid or unassigned resource %s [%016llx - %016llx] length [%016llx]\n", + io ? "io" : "mem", start, end, len); + + return false; +} + +static void acpi_dev_memresource_flags(struct resource *res, u64 len, + u8 write_protect, bool window) +{ + res->flags = IORESOURCE_MEM; + + if (!acpi_dev_resource_len_valid(res->start, res->end, len, false)) + res->flags |= IORESOURCE_DISABLED; if (write_protect == ACPI_READ_WRITE_MEMORY) - flags |= IORESOURCE_MEM_WRITEABLE; + res->flags |= IORESOURCE_MEM_WRITEABLE; if (window) - flags |= IORESOURCE_WINDOW; - - return flags; + res->flags |= IORESOURCE_WINDOW; } static void acpi_dev_get_memresource(struct resource *res, u64 start, u64 len, @@ -56,7 +72,7 @@ static void acpi_dev_get_memresource(struct resource *res, u64 start, u64 len, { res->start = start; res->end = start + len - 1; - res->flags = acpi_dev_memresource_flags(len, write_protect, false); + acpi_dev_memresource_flags(res, len, write_protect, false); } /** @@ -77,24 +93,18 @@ bool acpi_dev_resource_memory(struct acpi_resource *ares, struct resource *res) switch (ares->type) { case ACPI_RESOURCE_TYPE_MEMORY24: memory24 = &ares->data.memory24; - if (!memory24->minimum && !memory24->address_length) - return false; acpi_dev_get_memresource(res, memory24->minimum, memory24->address_length, memory24->write_protect); break; case ACPI_RESOURCE_TYPE_MEMORY32: memory32 = &ares->data.memory32; - if (!memory32->minimum && !memory32->address_length) - return false; acpi_dev_get_memresource(res, memory32->minimum, memory32->address_length, memory32->write_protect); break; case ACPI_RESOURCE_TYPE_FIXED_MEMORY32: fixed_memory32 = &ares->data.fixed_memory32; - if (!fixed_memory32->address && !fixed_memory32->address_length) - return false; acpi_dev_get_memresource(res, fixed_memory32->address, fixed_memory32->address_length, fixed_memory32->write_protect); @@ -102,7 +112,8 @@ bool acpi_dev_resource_memory(struct acpi_resource *ares, struct resource *res) default: return false; } - return true; + + return !(res->flags & IORESOURCE_DISABLED); } EXPORT_SYMBOL_GPL(acpi_dev_resource_memory); @@ -186,7 +197,6 @@ bool acpi_dev_resource_address_space(struct acpi_resource *ares, acpi_status status; struct acpi_resource_address64 addr; bool window; - u64 len; u8 io_decode; status = acpi_resource_to_address64(ares, &addr); @@ -199,10 +209,9 @@ bool acpi_dev_resource_address_space(struct acpi_resource *ares, switch(addr.resource_type) { case ACPI_MEMORY_RANGE: - len = addr.address.maximum - addr.address.minimum + 1; - res->flags = acpi_dev_memresource_flags(len, - addr.info.mem.write_protect, - window); + acpi_dev_memresource_flags(res, addr.address.address_length, + addr.info.mem.write_protect, + window); break; case ACPI_IO_RANGE: io_decode = addr.address.granularity == 0xfff ? @@ -236,7 +245,6 @@ bool acpi_dev_resource_ext_address_space(struct acpi_resource *ares, { struct acpi_resource_extended_address64 *ext_addr; bool window; - u64 len; u8 io_decode; if (ares->type != ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64) @@ -250,10 +258,10 @@ bool acpi_dev_resource_ext_address_space(struct acpi_resource *ares, switch(ext_addr->resource_type) { case ACPI_MEMORY_RANGE: - len = ext_addr->address.maximum - ext_addr->address.minimum + 1; - res->flags = acpi_dev_memresource_flags(len, - ext_addr->info.mem.write_protect, - window); + acpi_dev_memresource_flags(res, + ext_addr->address.address_length, + ext_addr->info.mem.write_protect, + window); break; case ACPI_IO_RANGE: io_decode = ext_addr->address.granularity == 0xfff ?