Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp658913ybp; Wed, 9 Oct 2019 02:06:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqyNzK3AhYHXBwD62pDflNUKxWSCjqasEVz8d25yb9IZcoSth8QjLlYlakTtwBNNEsl9TNnI X-Received: by 2002:a17:907:101b:: with SMTP id ox27mr1802831ejb.130.1570611990697; Wed, 09 Oct 2019 02:06:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570611990; cv=none; d=google.com; s=arc-20160816; b=MUTI1kbcDIKfGuKV/m9sezhoU7lsNIv6BntCiH9O9f4MNcMEwxwn7D6s/AWSGyjznY 5Hf6cPAU02Lue4JbUvrM+nr0NYOWyAZ+nZk63eeNW2eLU2yX1jOLBbzmpRC12AdfElqX TR77uPIGdK9mlNDYxZxBN4bafGwq1vqyFGSIX2RUWbtSTRQ/4HHhZif0U/l7CAZ3HnPz cjQOutevx+Zf8g+75yvbGxeQbve+GmHjUkdbvtfW0XAmVFFUqyuYNr2XU/ExeJCJby9D ZFprsp+NlDbIH9czrxlU6e8rH7+9GVZWOgv9FaOnkpN9t56QF9FHxDdK+JE96kGLUInR 767g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:dkim-signature; bh=jEegimTNJbOHR+TosMTLwdjur6SlXV6/KlNYDlpB+PY=; b=l3Izrg27UyDn7nyAnr0ghRVZENYIlXc7y4TeUgjzx6NK6Ti0vzB3OLvtor1n9ZL0NI 9lDDHJaBJJGglG+TJzVRmCgrdW3q3IGWI9Jd2Uu/kPfIk6NCutsyRk2oLd34VKvgFcSB 7ceUFdGBxstafewK7RJW/JCELzatyk+MRkiNzbOdALAXBa36Msso+60EhruhixNnnINR /r9RsjQ8F/sPTL8gJl4lekmH2IXWrUsy1QfUkSAucs1rUEgCUlARCz61owpTAvcb7iYL hmpSQkiN5PMYS1KCoKveEiT8XaFXmfOfjwleD29Rtj10Gnew1pb2KR6eyiXTEiBIePZ9 iyjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=msHx5Po+; 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=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h91si986029edd.270.2019.10.09.02.06.06; Wed, 09 Oct 2019 02:06:30 -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=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=msHx5Po+; 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=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727035AbfJIJEB (ORCPT + 99 others); Wed, 9 Oct 2019 05:04:01 -0400 Received: from fllv0015.ext.ti.com ([198.47.19.141]:44202 "EHLO fllv0015.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725776AbfJIJEB (ORCPT ); Wed, 9 Oct 2019 05:04:01 -0400 Received: from fllv0035.itg.ti.com ([10.64.41.0]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id x9993t0W028585; Wed, 9 Oct 2019 04:03:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1570611835; bh=jEegimTNJbOHR+TosMTLwdjur6SlXV6/KlNYDlpB+PY=; h=Subject:To:References:From:Date:In-Reply-To; b=msHx5Po+NS1W0yV7jb93vkkntFsEo2/fRtzCPbZeUcmzvjub+48Ad0mNAkFa5RZ4L VWQXJg+kABGl4W/oR9lOFqJBJwSenFn3Rlv/QmLVAK4W6AyoGgM5obdtHTKF0y6csv 7AJQXBMkbQsJ2Fuuz+l15U7ci/Hv9386Xp1Hswdk= Received: from DLEE111.ent.ti.com (dlee111.ent.ti.com [157.170.170.22]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTP id x9993tSJ093996; Wed, 9 Oct 2019 04:03:55 -0500 Received: from DLEE108.ent.ti.com (157.170.170.38) by DLEE111.ent.ti.com (157.170.170.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Wed, 9 Oct 2019 04:03:52 -0500 Received: from fllv0039.itg.ti.com (10.64.41.19) by DLEE108.ent.ti.com (157.170.170.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5 via Frontend Transport; Wed, 9 Oct 2019 04:03:52 -0500 Received: from [172.24.190.233] (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id x9993oSZ076819; Wed, 9 Oct 2019 04:03:52 -0500 Subject: Re: [PATCH] PCI: endpoint: cast the page number to phys_addr_t To: Alan Mikhak , , , , Bjorn Helgaas , Palmer Dabbelt , Paul Walmsley References: <1570240177-8934-1-git-send-email-alan.mikhak@sifive.com> From: Kishon Vijay Abraham I Message-ID: <69ec3cdf-a7e8-d926-ccba-a1edbb92348d@ti.com> Date: Wed, 9 Oct 2019 14:33:26 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Alan, On 07/10/19 11:14 PM, Alan Mikhak wrote: > On Fri, Oct 4, 2019 at 6:49 PM Alan Mikhak wrote: >> >> From: Alan Mikhak >> >> Modify pci_epc_mem_alloc_addr() to cast the variable 'pageno' >> from type 'int' to 'phys_addr_t' before shifting left. This >> cast is needed to avoid treating bit 31 of 'pageno' as the >> sign bit which would otherwise get sign-extended to produce >> a negative value. When added to the base address of PCI memory >> space, the negative value would produce an invalid physical >> address which falls before the start of the PCI memory space. >> >> Signed-off-by: Alan Mikhak Thanks for the patch. The change-log title should start with "capitalized verb" linux-pci follows certain guidelines listed here https://lore.kernel.org/r/20171026223701.GA25649@bhelgaas-glaptop.roam.corp.google.com/ Once that gets fixed Acked-by: Kishon Vijay Abraham I >> --- >> drivers/pci/endpoint/pci-epc-mem.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/drivers/pci/endpoint/pci-epc-mem.c b/drivers/pci/endpoint/pci-epc-mem.c >> index 2bf8bd1f0563..d2b174ce15de 100644 >> --- a/drivers/pci/endpoint/pci-epc-mem.c >> +++ b/drivers/pci/endpoint/pci-epc-mem.c >> @@ -134,7 +134,7 @@ void __iomem *pci_epc_mem_alloc_addr(struct pci_epc *epc, >> if (pageno < 0) >> return NULL; >> >> - *phys_addr = mem->phys_base + (pageno << page_shift); >> + *phys_addr = mem->phys_base + ((phys_addr_t)pageno << page_shift); >> virt_addr = ioremap(*phys_addr, size); >> if (!virt_addr) >> bitmap_release_region(mem->bitmap, pageno, order); >> -- >> 2.7.4 >> > > Hi Kishon, > > This issue was observed when requesting pci_epc_mem_alloc_addr() > to allocate a region of size 0x40010000ULL (1GB + 64KB) from a > 128GB PCI address space with page sizes being 64KB. This resulted > in 'pageno' value of '0x8000' as the first available page in a > contiguous region for the requested size due to other smaller > regions having been allocated earlier. With 64KB page sizes, > the variable 'page_shift' holds a value of 0x10. Shifting 'pageno' > 16 bits to the left results in an 'int' value whose bit 31 is set. > > [ 10.565256] __pci_epc_mem_init: mem size 0x2000000000 page_size 0x10000 > [ 10.571613] __pci_epc_mem_init: mem pages 0x200000 bitmap_size > 0x40000 page_shift 0x10 > > PCI memory base 0x2000000000 > PCI memory size 128M 0x2000000000 > page_size 64K 0x10000 > page_shift 16 0x10 > pages 2M 0x200000 > bitmap_size 256K 0x40000 > > [ 702.050299] pci_epc_mem_alloc_addr: size 0x10000 order 0x0 pageno > 0x4 virt_add 0xffffffd0047b0000 phys_addr 0x2000040000 > [ 702.061424] pci_epc_mem_alloc_addr: size 0x10000 order 0x0 pageno > 0x5 virt_add 0xffffffd0047d0000 phys_addr 0x2000050000 > [ 702.203933] pci_epc_mem_alloc_addr: size 0x40010000 order 0xf > pageno 0x8000 virt_add 0xffffffd004800000 phys_addr 0x1f80000000 > [ 702.216547] Oops - store (or AMO) access fault [#1] > ::: > [ 702.310198] sstatus: 0000000200000120 sbadaddr: ffffffd004804000 > scause: 0000000000000007 Thank you Alan for testing this and sending a patch to fix it. Cheers Kishon