Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1041085AbdDUOak (ORCPT ); Fri, 21 Apr 2017 10:30:40 -0400 Received: from mail-ve1eur01on0078.outbound.protection.outlook.com ([104.47.1.78]:46666 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1035540AbdDUOah (ORCPT ); Fri, 21 Apr 2017 10:30:37 -0400 From: Roy Pledge To: Mark Rutland , Haiying Wang CC: "linux-kernel@vger.kernel.org" , "gregkh@linuxfoundation.org" , "linux-arm-kernel@lists.infradead.org" , "stuyoder@gmail.com" , "catalin.marinas@arm.com" , "will.deacon@arm.com" , Dave Lapp Subject: Re: [PATCH 1/3] arm64: extend ioremap for cacheable non-shareable memory Thread-Topic: [PATCH 1/3] arm64: extend ioremap for cacheable non-shareable memory Thread-Index: AQHSug083bI1G651QkCvievP+Ty55aHPioyAgAAV84A= Date: Fri, 21 Apr 2017 14:30:32 +0000 Message-ID: <7C745CC3-3E91-4A8A-8DAB-0FA4E50DF08B@nxp.com> References: <1492716858-24509-1-git-send-email-Haiying.Wang@nxp.com> <1492716858-24509-2-git-send-email-Haiying.Wang@nxp.com> <20170421091156.GA6406@leverpostej> In-Reply-To: <20170421091156.GA6406@leverpostej> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=none action=none header.from=nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [99.246.4.217] x-microsoft-exchange-diagnostics: 1;VI1PR04MB3165;7:TAHUwma8mOYJ0OhMKE1tCcnJR2oHXWKUtOP01B2mdT4M5FcoajQBpPRwP9KLtkaifLn0swOdzmuk4vnYNZuTtjp+K5u5XsNe4x5NvPhjAzNiBBIm7N9/pvI+dkyyUPrWNIQ6/dZR8qGml6KUQJqXXR9qtfCVLy07AYTwx4wGsEleBZcvdk8ikVQ4x7DXWMyUbUwzb1Xp117l2TOIKyD/z+TWSVv5/QCfbPQ1zV3jFMR7o7Jh2x+qLE/Imt8jLZJWP/KIqr9mxdtSRzA1XqIZ8ymHORREqEAvdf8ezOttuPm2UoGn3HF+txp08nxSvlBtyYmYhQ8jTIDWtwR/vJOw6w== x-forefront-antispam-report: SFV:SKI;SCL:-1SFV:NSPM;SFS:(10009020)(6009001)(39840400002)(39410400002)(39850400002)(39400400002)(39450400003)(39860400002)(377454003)(377424004)(24454002)(966004)(25786009)(6636002)(122556002)(6246003)(4326008)(53546009)(2950100002)(54356999)(2906002)(8936002)(50986999)(229853002)(6486002)(77096006)(76176999)(3846002)(39060400002)(53936002)(102836003)(6116002)(83716003)(1720100001)(33656002)(305945005)(54906002)(7736002)(5660300001)(66066001)(82746002)(86362001)(38730400002)(6306002)(189998001)(3280700002)(6506006)(6512007)(6436002)(2900100001)(8676002)(3660700001)(99286003)(81166006)(36756003);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR04MB3165;H:VI1PR04MB3216.eurprd04.prod.outlook.com;FPR:;SPF:None;MLV:ovrnspm;PTR:InfoNoRecords;LANG:en; x-ms-office365-filtering-correlation-id: 15bcd66a-1527-45e1-ac15-08d488c2f7cb x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(2017030254075)(48565401081)(201703131423075)(201703031133081)(201702281549075);SRVR:VI1PR04MB3165; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(180628864354917)(185117386973197)(227817650892897)(258649278758335); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6040450)(601004)(2401047)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3002001)(6055026)(6041248)(20161123555025)(20161123564025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(20161123562025)(6072148);SRVR:VI1PR04MB3165;BCL:0;PCL:0;RULEID:;SRVR:VI1PR04MB3165; x-forefront-prvs: 02843AA9E0 spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="utf-8" Content-ID: <345CF1A750257C499B1CAD51445423F2@eurprd04.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Apr 2017 14:30:32.6054 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB3165 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by mail.home.local id v3LEUjN5015658 Content-Length: 5571 Lines: 114 These transactions are done in HW via an ACP port which if I remember correctly only supports non coherent transactions. I will need to go back and check through email conversations I had with Catalin last year when debugging an issue using this mechanism (cacheable/nonshareable mapping) but it was deemed to be valid ARM setup architecturally for this type of device. Just for some background the page the QBMan device presented to a core is only accessed by a single core (i.e. SW portals are core affine). In this model each page is always mapped as non shareable and another core will never access it. The important factor is that it is not DDR memory being mapped non sharable, but a non-coherent master on the bus in our SoC. I agree regular RAM shouldn’t be mapped this way but we cannot map this device as cacheable/shareable (coherent) on CCN-504 devices without getting exceptions from the CCN-504. Treating it as non cacheable is functionally OK but performance suffers in that case. Your help will be appreciated as we want to get support for these devices with good performance in upstream kernels. Roy On 2017-04-21, 5:11 AM, "Mark Rutland" wrote: Hi, I notice you missed Catalin and Will from Cc. In future, please ensure that you Cc them when altering arm64 arch code. On Thu, Apr 20, 2017 at 03:34:16PM -0400, Haiying Wang wrote: > NXP arm64 based SoC needs to allocate cacheable and > non-shareable memory for the software portals of > Queue manager, so we extend the arm64 ioremap support > for this memory attribute. NAK to this patch. It is not possible to safely use Non-Shareable attributes in Linux page tables, given that these page tables are shared by all PEs (i.e. CPUs). My understanding is that if several PEs map a region as Non-Shareable, the usual background behaviour of the PEs (e.g. speculation, prefetching, natural eviction) mean that uniprocessor semantics are not guaranteed (i.e. a read following a write may see stale data). For example, in a system like: +------+ +------+ | PE-a | | PE-b | +------+ +------+ | L1-a | | L1-b | +------+ +------+ || || +----------------+ | Shared cache | +----------------+ || +----------------+ | Memory | +----------------+ ... you could have a sequence like: 1) PE-a allocates a line into L1-a for address X in preparation for a store. 2) PE-b allocates a line into L1-b for the same address X as a result of speculation. 3) PE-a makes a store to the line in L1-a. Since address X is mapped as Non-shareable, no snoops are performed to keep other copies of the line in sync. 4) As a result of explicit maintenance or as a natural eviction, L1-a evicts its line into shared cache. The shared cache subsequently evicts this to memory. 5) L1-b evicts its line to shared cache as a natural eviction. 6) L1-a fetches the line from shared cache in response to a load by PE-a, returning stale data (i.e. the store is lost). No amount of cache maintenance can avoid this. In general, Non-Shareable mappings are a bad idea. Thanks, Mark. > Signed-off-by: Haiying Wang > --- > arch/arm64/include/asm/io.h | 1 + > arch/arm64/include/asm/pgtable-prot.h | 1 + > 2 files changed, 2 insertions(+) > > diff --git a/arch/arm64/include/asm/io.h b/arch/arm64/include/asm/io.h > index 0c00c87..b6f03e7 100644 > --- a/arch/arm64/include/asm/io.h > +++ b/arch/arm64/include/asm/io.h > @@ -170,6 +170,7 @@ extern void __iomem *ioremap_cache(phys_addr_t phys_addr, size_t size); > #define ioremap_nocache(addr, size) __ioremap((addr), (size), __pgprot(PROT_DEVICE_nGnRE)) > #define ioremap_wc(addr, size) __ioremap((addr), (size), __pgprot(PROT_NORMAL_NC)) > #define ioremap_wt(addr, size) __ioremap((addr), (size), __pgprot(PROT_DEVICE_nGnRE)) > +#define ioremap_cache_ns(addr, size) __ioremap((addr), (size), __pgprot(PROT_NORMAL_NS)) > #define iounmap __iounmap > > /* > diff --git a/arch/arm64/include/asm/pgtable-prot.h b/arch/arm64/include/asm/pgtable-prot.h > index 2142c77..7fc7910 100644 > --- a/arch/arm64/include/asm/pgtable-prot.h > +++ b/arch/arm64/include/asm/pgtable-prot.h > @@ -42,6 +42,7 @@ > #define PROT_NORMAL_NC (PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_DIRTY | PTE_WRITE | PTE_ATTRINDX(MT_NORMAL_NC)) > #define PROT_NORMAL_WT (PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_DIRTY | PTE_WRITE | PTE_ATTRINDX(MT_NORMAL_WT)) > #define PROT_NORMAL (PROT_DEFAULT | PTE_PXN | PTE_UXN | PTE_DIRTY | PTE_WRITE | PTE_ATTRINDX(MT_NORMAL)) > +#define PROT_NORMAL_NS (PTE_TYPE_PAGE | PTE_AF | PTE_PXN | PTE_UXN | PTE_DIRTY | PTE_WRITE | PTE_ATTRINDX(MT_NORMAL)) > > #define PROT_SECT_DEVICE_nGnRE (PROT_SECT_DEFAULT | PMD_SECT_PXN | PMD_SECT_UXN | PMD_ATTRINDX(MT_DEVICE_nGnRE)) > #define PROT_SECT_NORMAL (PROT_SECT_DEFAULT | PMD_SECT_PXN | PMD_SECT_UXN | PMD_ATTRINDX(MT_NORMAL)) > -- > 2.7.4 > > > _______________________________________________ > linux-arm-kernel mailing list > linux-arm-kernel@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel