Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp4597338ybp; Mon, 7 Oct 2019 10:47:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqyJuGgD5awxNUK+w+uhSkP2Azx1uMkSGPK5Oy1hVOsYrNtSl8SkHHLq1FXJr8A/NOYn3mD1 X-Received: by 2002:a17:906:b30b:: with SMTP id n11mr25387914ejz.35.1570470459778; Mon, 07 Oct 2019 10:47:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570470459; cv=none; d=google.com; s=arc-20160816; b=eDmYin/hHVrah58zQDgBbCCbp/NbttfQFZEINAQvqHqs3hm+fv5VBYZXYar/TsHH1T HW0TaWg9yjdK+gioo4AK2J1RWfjr/TzqpTATId10AHhmJx4XFhlyVTU9xir9kwHIQjf2 HIQBN11Dye/S8vU1tDMMUaLuZ7BsQPLsIPdRdgyuBjy5cZHuumcgRoJx2GoQC+qfRWj+ ZqXod3+1qzO09Q3s9HDAXqNl7rW+ZwviYmAaanDyHGxWjNq978mUNd4g+oxYk0cyQLUx lhCjV5/YvkgSMqtymG6zVfkoyctI/9jGa/+EV2nMU9oXl4f9V7kjRtF/0+v3eEqrfDXY PvRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=vk7i14T/JR7YS23mvVE1tUhQjiWMuR9VHE86a98WunI=; b=Q1UTNMWWPhiqp9onXwzksNSwipH6+efKcOulMjraOWrDOt+LJU5nmxW9uqXIAKE1kG TUn+9HIGXmi2c8VCH1Y8fU9r7bVCw/BlMgOiyfkDGlUYlwJlI2xUoqlA7bJDg2vOJttw dW40nvsGeKCdqIds8a/6VByjuswhxAdqjtOCz2YNTbjlLSwIhPOd5XWTy9EYt5r4MKFh eTdd08HyTXLDdsg20aUmr1sOoA2vDx+vJTXe8LY6U1puQ7x4fClhIPEYEHPTJrDT9OIH fktjuYhyMRrz/hTbDUehcbEAlfer5PgQUJiOsNxYPmSMlM4G1uVctvCRJkehax2y9udG 8oKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=OLLwDwGc; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r1si7036640ejp.287.2019.10.07.10.47.16; Mon, 07 Oct 2019 10:47:39 -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=@sifive.com header.s=google header.b=OLLwDwGc; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728915AbfJGRof (ORCPT + 99 others); Mon, 7 Oct 2019 13:44:35 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:38627 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728545AbfJGRof (ORCPT ); Mon, 7 Oct 2019 13:44:35 -0400 Received: by mail-lj1-f195.google.com with SMTP id b20so14631768ljj.5 for ; Mon, 07 Oct 2019 10:44:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=vk7i14T/JR7YS23mvVE1tUhQjiWMuR9VHE86a98WunI=; b=OLLwDwGcq0XWYoIOVOg3f18hRqsB+0FRgBDO0OmmxtqGQYby0JB5u0UHjDXgij9vYo Se5/pU/H1eTqNRcFiWOtVL5Hx5zYOR44QeVE0UBOryjbfM15v53lLA/oM8EV26gbHEN7 UXRvKQeEhMekI8rhDX+Y0qFpuCB18WULcN5R+UjJb0Frfkc49Dhr7MrjPLZKDwKFhS3E 9Fre4eNitanYVJmDpA6UEHCi9lUTvmIFQhYGhaNay+PEgLNtF1y3aAh3aEwIK3/Sy26M 27co8CrSYmbGd8qfcq7SPlpqlhAPLlmBMcmkumdfymHaf5LfUlqhLclwLOZEcSMx8hl5 Ndlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=vk7i14T/JR7YS23mvVE1tUhQjiWMuR9VHE86a98WunI=; b=eUDmwkYokdDoWFC3pEVxXFLJJQ0sK6+I0V2IFYgaaiQ0R7gctWeYkNvusGC248MWZI xSqrx2ngeDe0Su1EQRDqGScFRN3b4vuHisCuLNyNl4hXAZ61/9GXUFO6A0zifnxMmAq9 4fDR0lBhGOSCSbRkmI01OJpF1U3iys6591rGC36USXm2LyTbySSgHgKXpazLLtYw8vNc 6QA6aKrk15rgOAzU1/eWcYa4MlR//BIxZV3mA+qCbme9SN99idsIJFSP/rWjHRaeXur7 DRg9ho8xjyFtpBH18kbT6qwEHBOjRFurZ7QSdnVCX+u2PSTqx2Zi66GcdA3Z7eCLa/Yx fgDw== X-Gm-Message-State: APjAAAXvsWE5ocItTAMfDkOz+lIe/qQ1KO7a0z/midBxQ2icXxsAf4OF zr1DLFktWVoWOYBmPbCF/Xge+aG4BWig2P8yr9vK8OBkpTs= X-Received: by 2002:a2e:8084:: with SMTP id i4mr19449238ljg.119.1570470272661; Mon, 07 Oct 2019 10:44:32 -0700 (PDT) MIME-Version: 1.0 References: <1570240177-8934-1-git-send-email-alan.mikhak@sifive.com> In-Reply-To: <1570240177-8934-1-git-send-email-alan.mikhak@sifive.com> From: Alan Mikhak Date: Mon, 7 Oct 2019 10:44:21 -0700 Message-ID: Subject: Re: [PATCH] PCI: endpoint: cast the page number to phys_addr_t To: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Kishon Vijay Abraham I , lorenzo.pieralisi@arm.com, Bjorn Helgaas , Palmer Dabbelt , Paul Walmsley 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 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 > --- > 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 Regards, Alan