From patchwork Mon May 30 14:15:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bogdan Purcareata X-Patchwork-Id: 9141537 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C33FB60754 for ; Mon, 30 May 2016 14:17:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9361827C23 for ; Mon, 30 May 2016 14:17:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 881C72819E; Mon, 30 May 2016 14:17:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EC15927C23 for ; Mon, 30 May 2016 14:17:32 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1b7NzI-0005YX-OL; Mon, 30 May 2016 14:16:12 +0000 Received: from mail-bn1on0075.outbound.protection.outlook.com ([157.56.110.75] helo=na01-bn1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1b7NzE-0005Qs-3a for linux-arm-kernel@lists.infradead.org; Mon, 30 May 2016 14:16:09 +0000 Received: from DM2PR03CA0026.namprd03.prod.outlook.com (10.141.96.25) by BY2PR0301MB1590.namprd03.prod.outlook.com (10.163.28.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.506.2; Mon, 30 May 2016 14:15:46 +0000 Received: from BN1AFFO11FD009.protection.gbl (2a01:111:f400:7c10::169) by DM2PR03CA0026.outlook.office365.com (2a01:111:e400:2428::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.506.9 via Frontend Transport; Mon, 30 May 2016 14:15:45 +0000 Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=nxp.com; lists.linux-foundation.org; dkim=none (message not signed) header.d=none; lists.linux-foundation.org; dmarc=none action=none header.from=nxp.com; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.158.2 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.158.2; helo=az84smr01.freescale.net; Received: from az84smr01.freescale.net (192.88.158.2) by BN1AFFO11FD009.mail.protection.outlook.com (10.58.52.69) with Microsoft SMTP Server (TLS) id 15.1.497.8 via Frontend Transport; Mon, 30 May 2016 14:15:45 +0000 Received: from localhost.localdomain (fsr-ub1464-106.ea.freescale.net [10.171.73.16]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id u4UEFghA015834; Mon, 30 May 2016 07:15:43 -0700 From: Bogdan Purcareata To: , Subject: [PATCH] iommu/arm-smmu: Properly initialize CBAR MemAttr Date: Mon, 30 May 2016 14:15:42 +0000 Message-ID: <1464617742-5493-1-git-send-email-bogdan.purcareata@nxp.com> X-Mailer: git-send-email 2.1.4 X-EOPAttributedMessage: 0 X-Matching-Connectors: 131090913455636814; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.158.2; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(1110001)(1109001)(339900001)(189002)(199003)(11100500001)(47776003)(551934003)(5001770100001)(49486002)(586003)(48376002)(106466001)(87936001)(229853001)(86362001)(85426001)(81166006)(33646002)(8676002)(8936002)(50466002)(50986999)(105606002)(1220700001)(189998001)(36756003)(50226002)(77096005)(5003940100001)(6806005)(2906002)(19580405001)(4326007)(19580395003)(92566002)(104016004)(5008740100001); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR0301MB1590; H:az84smr01.freescale.net; FPR:; SPF:Fail; MLV:sfv; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD009; 1:7/+MWt54LLG/WIojep1jw7etS9LX9QV8E1QeXJHiD03PY8SqP/HrgUto7u8lWFAtxUwK4+0W78VebZJlRDKxr91RMU+i4VJBVgX1kZc00rMG4k+8veJsKmBOfU0MXTkdRnO+GND/pSkLCM7QGcJm7/6tLzXLAjpypkumSj6Sb4iOprIFpYJAFxiqDr4mxow2Pvmu3eujsQ/xyjaloMhXeExRv/d89NMRaMZqdwe5RHDubXevWi8OotuRwxWwzguUr7OKPMvugB4tU2yYuwdwvFv5ug/dT6e/ku4l4Dv3FqP89PX4Zyx1gItESBCFOwNnoy1dXRnSvj6HLI5xdGTckRQJTZSB+On0QJASqyGkOjc3zDuC/Y3g9mC+DK3c7wbhl8zL6GnHLTw+ZZWQSV0KcULQ6wcK6qoKqXbb6B9gX6jjbA4nQT8XbNWjITS6gCb2SrzyR9M/piM5ZsjjWhNWvp8VkGxUnIGsDUnrabK8eWUdok+3Ld0KWOM37aF+gP0JjRqa0OMl22Cm/Bokf4XfbafZRbY8N6qnvYyAAnFIqAsubmGGRR2lqyffiCWrfLfD0PlUnsQfb2sb28UYIQvkf4/1/pOfgSQOF0ZUMtU4CwRPP4DtcQKfmIvIIES5bNrz MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 4c4cbf20-6b6b-45cc-f64e-08d38894e431 X-Microsoft-Exchange-Diagnostics: 1; BY2PR0301MB1590; 2:lWp7N8bos1aaqmjOxC+NwvJ6KJvX8s45DymN45GbAgUoCw7EzhNI4BMl3x6UnWtQ5Ir+uzzO5atiLzlSE5Ce0AIOzi2A16dSty3BC974j1/Sq6jHUUM5O8oe39wny5QCgiatym13julFb245Ex41lGOkfWN8Lsz3niNmzPUEVAb1vN4ukAiYclSzJFtqJP4p; 3:XpAGitDjVkoUZKcV+vDznMgUzUdJD9++sk2q6N2r0hTTZjULyCeObxHKXnaCFfBW+JSTPk0tH7p78YSvrNqoAinqmve6Ve7joPpujVUak46ILE61YkmMEQdpk6SRGBv5o4ykad6MM0bnFjFslD+1/sW40nPOEYbCHtorCMzBEUsjdYnfyDdgtc1RPaQ0jpHTVp1scwv/w5tj7qfV9RyRLSo9Q7CujO5w6LGcFIgIjqk=; 25:w07RcUfMl8x2owye4zsmCOw7GXd+cNi/stQUZ9s3kyN/b1xeEmBolQGUv5Mw8muKRoeSWSx6N+eNZiTq+Ihc2vwakB3TjCZJhbebFw51feT9sA6sh9TmA3NC8gttof+DiaW5Wr6zR688vWvXgF00nR9CpmPXWshJM90VGyisZunOsgCDNXhKvQYw0TqjA4KuS4s2HKSWYZ8wyDqF2HKi/wQQTFe/85SyxQhxfri92u/adA7HezO+Fqe0U8iiwO6azdmrsYIHIgq9WK1d2sLH8nGaTwDF5KIpbYsZzupy8+PCMIKNr7v4RyrNVO3l5SsiZIv0eiM2ak7AOnNDQz+LZ1/H1digl5VvVDVfxQGbgcv4f5QW3pnG8H6Wr74se90MoTHPncIQZZGJYDj5JZ9Bp2fEOhuzn2vkqK5MxHMSMh0= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY2PR0301MB1590; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(13017025)(13023025)(13024025)(13015025)(5005006)(8121501046)(13018025)(3002001)(10201501046)(6055026); SRVR:BY2PR0301MB1590; BCL:0; PCL:0; RULEID:(400006); SRVR:BY2PR0301MB1590; X-Microsoft-Exchange-Diagnostics: 1; BY2PR0301MB1590; 4:o5rYcBvutrekN68ur/gmg5Z61+GHYgllLIb/uXAwSTR8bSd2ROFW9e1YRY2H5vz5Vx01Au6QJ2DXi9w0nvyDDQKt2WtTDNwuLTBfZDFEs2neSGtaPdb60vPGJoChLM41GZNTtbXtokYoR6IyNo/L1FmP9ItgNcijkFKzeBk9zQI8WqgjawWGqZtBPfB6ccne5UrTbiOBdmoCPmHFRVis49cYBiuaVFL2mDObGhaSe8TQQMWEIypnFRxeCMKFvJEQYOEdQdcFvoOV/4MV3Hi/mNG1HO0xoMvC4xPzcagFMepZVvUgGiwkIXmFv5zCeWopav/DKuf1muKtTTzSCP2H6xGO3/mw2yK0fUmjaFmLQ1v5LYkuep5qI3VF3yzSgMYOeOQNjh+ctmEpOrBS6mopsokX0Z867t1e5hyN4dYQwAlaNvhsS4GFugzerN2i8gp9FDdPeOLMh8VTE9m334WvsZRYJax9RDBpcqNNs8nKFAjn47yfU2VRkIwbAYPSKgYgKiBj2xN85PQvzhYHaQJusQ== X-Forefront-PRVS: 09583628E0 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY2PR0301MB1590; 23:2OQM2VtdslXo7mRzBPPq2UG9dEV1T0wuDdpOqWf?= =?us-ascii?Q?6vIFU445w3N9sb2i5g/3z5m7ko3/qOGy58Y7W9EESaG/zcea6p9YuhuxOhiF?= =?us-ascii?Q?wOlyvGBdP1Vks7+VN2X1oG3Jny4ibLUrTOJ7lhE0mG4jO5mA0frGj1ku7gr3?= =?us-ascii?Q?VV9EYa5nWYNVXnkObAMgRfkpfMq6NjeAWKZvqKvOusZkW8r/i0c8i5DobDKr?= =?us-ascii?Q?sb4ulO8pCZfopJEQlGkBysBcaYI23gjJq2IGC5SXZqsmhz844YLVHZJviag3?= =?us-ascii?Q?VmgtCbeOgzB4J4XAZfNgJUUvuPM/eliKcq5JGoJ64ig3kUaF4KERs7wIx8zi?= =?us-ascii?Q?DCyLF2Arz77l8+x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Mh4Hwxm9rhGw4fxoQefO4xTlusdo=; 24:/0GIMzY7C5z0vtaDlfcSQzmLsRt9HZ4u4YaMJ5aX3sv7PLqnvGSOxdEgNyn45OadR++h+v8m4rWnaFOjcFhIcUL/Za0u0+xv3CJsvI5fraU=; 7:y5nW07ulmbzy2BLc8B819BwSzhzRsvewlQFyVRCSQOzyK6uYsE7TMC7yDFgVfQuTTfoQmKWT7DC/01K51XRjh/mEEzuzBD/g76LyrX5WH+10lVyvaz1mDK/FyQhgCPPT0ZiQKoqM/vsPrDXTqfK0SBzR1Y1Da8vcFG6EMLDobMq6neA6b2z/BUKyKus3Uwav SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 May 2016 14:15:45.2204 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[192.88.158.2]; Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR0301MB1590 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160530_071608_424645_2986338C X-CRM114-Status: GOOD ( 13.47 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: iommu@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Currently, when initializing the CBAR memattr attributes to the weakest values, it is expected that the final ones will be declared in the TTBCR register (SMMU_CBn_TCR). This is not required when CBAR type consists of a stage 1 translation followed by a stage 2 bypass. This is the case when assigning a VFIO PCI device to a KVM guest. Overriding the default transaction attributes to writeback cacheable results in the device no longer working in the guest (the adapter requires explicit flushes on the descriptor rings memory). Update the context init routine to initialize the CBAR MemAttr field only if there's a stage 1 followed by a stage 2 translation. Signed-off-by: Bogdan Purcareata --- drivers/iommu/arm-smmu.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c index ff7a392..1400ec9 100644 --- a/drivers/iommu/arm-smmu.c +++ b/drivers/iommu/arm-smmu.c @@ -765,13 +765,14 @@ static void arm_smmu_init_context_bank(struct arm_smmu_domain *smmu_domain, { u32 reg; u64 reg64; - bool stage1; + bool stage1, stage1_stage2; struct arm_smmu_cfg *cfg = &smmu_domain->cfg; struct arm_smmu_device *smmu = smmu_domain->smmu; void __iomem *cb_base, *gr1_base; gr1_base = ARM_SMMU_GR1(smmu); stage1 = cfg->cbar != CBAR_TYPE_S2_TRANS; + stage1_stage2 = cfg->cbar == CBAR_TYPE_S1_TRANS_S2_TRANS; cb_base = ARM_SMMU_CB_BASE(smmu) + ARM_SMMU_CB(smmu, cfg->cbndx); if (smmu->version > ARM_SMMU_V1) { @@ -793,15 +794,19 @@ static void arm_smmu_init_context_bank(struct arm_smmu_domain *smmu_domain, /* * Use the weakest shareability/memory types, so they are - * overridden by the ttbcr/pte. + * overridden by the ttbcr/pte. This happens only if the stage + * 1 is followed by a stage 2 translation. */ - if (stage1) { + if (stage1_stage2) { reg |= (CBAR_S1_BPSHCFG_NSH << CBAR_S1_BPSHCFG_SHIFT) | (CBAR_S1_MEMATTR_WB << CBAR_S1_MEMATTR_SHIFT); - } else if (!(smmu->features & ARM_SMMU_FEAT_VMID16)) { + } + + if (!stage1 && !(smmu->features & ARM_SMMU_FEAT_VMID16)) { /* 8-bit VMIDs live in CBAR */ reg |= ARM_SMMU_CB_VMID(smmu, cfg) << CBAR_VMID_SHIFT; } + writel_relaxed(reg, gr1_base + ARM_SMMU_GR1_CBAR(cfg->cbndx)); /* TTBRs */