Received: by 10.192.165.148 with SMTP id m20csp4780120imm; Tue, 8 May 2018 14:21:26 -0700 (PDT) X-Google-Smtp-Source: AB8JxZosJ4kn9ZlyO9BezBH5e08bySgKUswxsD9Tw/HRRRE0gmzbhEKuxKI6S4jsRFOeF+DT9nDD X-Received: by 2002:a17:902:57d8:: with SMTP id g24-v6mr43717237plj.337.1525814486905; Tue, 08 May 2018 14:21:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525814486; cv=none; d=google.com; s=arc-20160816; b=SBUmyg/kJBVu8QAQiMZEYDSrSxOYMlRco7PcKydteMXF0HsYtfWWE1rJFuuvhJYekU lGEAE0XdoCPL5zdNy3h+zcf4BcrLu9VblMsxY7i9a2n7Yh6jS3QME5qJE7eH4WKSAGnT 2+LlS/XL0x9NB26H9Buhv8+zHLO+pRggy4+a700AG6UEh3T33iDWnEndko7N0CdaID3Z aPLpnfj76cBaChaOp00L/LpODMmIIdsGPUbikp4j8kfPT6Pu037YLa7Gzj9P9idZv/SK xXk0EZ6fPXo5yJwC/Q5otvKa4QwbQmEeeugQqdYG43Xmy/66eIsFmkMUmJ7+F9ZsDPXg 6FjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=6xxrEz6h41DBQBQo6sa3e0rPsjdnCo2P75Y38A9H0Yo=; b=bJthNc1tR3BDDFR5aTOBFsoL5u3hUg48wF1TH/19dBth0QNccqh22FygXPKXflYcsS 6SRjox3YJgVYRAh6Tdyo73cevuLK3rTvLFfQluVpwN2QV5SnhiiVKk6jxlAV39EW+FqD kQBYlABpTbzJ7XEkjzC3MRVE0dT8Phsbq2xtoydyzRkWxCAJL0Z0W1TEHubVtcXtgO1A tJaUMXIsknn1c5cMr0fTC/cA9TMaG3oF+WY02e5eJvvdwGEcr5f8SkSgPzZccVpiu4ck q4vBhp0nGRMeLucCsLzL3s46f4yUe/R43aFK2cs0ZFmY21jUqrrAMvCOHSgAaMSlqZjT 5bUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=pqlILVrs; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w23-v6si24830670plq.214.2018.05.08.14.21.12; Tue, 08 May 2018 14:21:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=pqlILVrs; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755953AbeEHVU1 (ORCPT + 99 others); Tue, 8 May 2018 17:20:27 -0400 Received: from mail-ot0-f193.google.com ([74.125.82.193]:40168 "EHLO mail-ot0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755544AbeEHVUY (ORCPT ); Tue, 8 May 2018 17:20:24 -0400 Received: by mail-ot0-f193.google.com with SMTP id n1-v6so37798032otf.7; Tue, 08 May 2018 14:20:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=6xxrEz6h41DBQBQo6sa3e0rPsjdnCo2P75Y38A9H0Yo=; b=pqlILVrsVSnKp6t4O96JpT5i/XqYeqCX9FP4bewHoq4zg3bkUcgETtSUUz+e7fHmXf U0c/oHA3r6y+21J9RXMPG6Yzn4ikSWtkZ3G7rWObHXyDjOk74Y2SKT+85xoPn9Dnwr4G Ejnsr11OgTE31xHneNVVSkfc6ulSs2YXhkRzGaedGu8F6zTKCvv72VFJjJyz2Fkyjo6Z 3bia4Muhv5MowtSoz929aXv1rCNaeEEEW30Du53Kf9xm+C4j7Ohyx1tNI/3rWGVnP0M+ h7oqgcbArWaO2c5NRWSr1Q9fwRfcLI4LPczf4k7uW+Ovh4rkNrS609w4rCaeHvpLqaTk VaoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=6xxrEz6h41DBQBQo6sa3e0rPsjdnCo2P75Y38A9H0Yo=; b=fLEpj/arsbhpB+31+vZ7y/CDDLHfDHks7Z04VBYQxXY+lHtoh5leeCpEtPw1LDubZk 9KXNKwOVkPPg8X7OQrX8Eswqi8UN51+Y3/skEdsY3eJ1GdlFm9DAEQdpaNzY007BrPTe h5PdWvJ+KgVhOGPcclTSJvyuh+8FHW1BHj5GDno9g8hGUmAL+XADyx4docGZx3404QZi pHVDddUM/wmvu3qKLdAv3710hChnMMfyckxR3+M7iyNfnfQDxkIWnVAE2IlE2G3zwflA UNE/Z1VQKBru2NVrkus4n96puZzxaOhW3m3h+wcvr5BwfejvenRqgeddn5JI+m24seRb o3ow== X-Gm-Message-State: ALKqPweMDohpr8KkQ2oJwqBpttTSqaW02ASoJ4BkYe5phNcNStpKMZpC 4WX6RezPYAGJvUp5ABM79k5uZ0zGiJhdv24OFZs= X-Received: by 2002:a9d:9d6:: with SMTP id 22-v6mr204364otz.291.1525814424053; Tue, 08 May 2018 14:20:24 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a9d:1468:0:0:0:0:0 with HTTP; Tue, 8 May 2018 14:20:23 -0700 (PDT) In-Reply-To: References: <1522480343-37669-1-git-send-email-xieyisheng1@huawei.com> <3699960.UXjPS91TgB@aspire.rjw.lan> From: "Rafael J. Wysocki" Date: Tue, 8 May 2018 23:20:23 +0200 X-Google-Sender-Auth: VEE3xCpQOBUAnSiNXqzc-5fFKUg Message-ID: Subject: Re: [PATCH v2 1/2] PCI ACPI: Avoid panic when PCI IO resource's size is not page aligned To: Yisheng Xie Cc: "Rafael J. Wysocki" , Bjorn Helgaas , Len Brown , Linux PCI , ACPI Devel Maling List , Linux Kernel Mailing List , Hanjun Guo , Jon Masters , Toshi Kani , tanxiaojun@huawei.com, Zhou Wang , Lorenzo Pieralisi , Sudeep Holla , Hanjun Guo Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 7, 2018 at 10:06 AM, Yisheng Xie wrote: > > > On 2018/5/1 17:28, Rafael J. Wysocki wrote: >>> drivers/acpi/pci_root.c | 2 +- >>> > 1 file changed, 1 insertion(+), 1 deletion(-) >>> > >>> > diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c >>> > index 6fc204a..b758ca3 100644 >>> > --- a/drivers/acpi/pci_root.c >>> > +++ b/drivers/acpi/pci_root.c >>> > @@ -746,7 +746,7 @@ static void acpi_pci_root_remap_iospace(struct resource_entry *entry) >>> > goto err; >>> > >>> > res->start = port; >>> > - res->end = port + length - 1; >>> > + res->end = PAGE_ALIGN(port + length) - 1; >> Shouldn't pci_remap_iospace() sanitize its arguments instead? > > Yeah, I thought that pci_remap_iospace() will be called at many place, and presently I > had not seen any problem at other place except acpi_pci_root_remap_iospace(). Anyway, > sanitize arguments in pci_remap_iospace() can resolve the problem more thoroughly, but > should more common, right? > > Therefore, is the follow change ok from your point of view? > > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c > index e597655..8607298 100644 > --- a/drivers/pci/pci.c > +++ b/drivers/pci/pci.c > @@ -3527,6 +3527,9 @@ int pci_remap_iospace(const struct resource *res, phys_addr_t phys_addr) > if (res->end > IO_SPACE_LIMIT) > return -EINVAL; > > + if (!PAGE_ALIGNED(vaddr) || !PAGE_ALIGNED(resource_size(res))) > + return -EINVAL; > + > return ioremap_page_range(vaddr, vaddr + resource_size(res), phys_addr, > pgprot_device(PAGE_KERNEL)); > #else I'd rather apply PAGE_ALIGN() to the arguments of ioremap_page_range() and call it anyway. It will fail if the mapping cannot be created.