Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp149699pxb; Thu, 21 Jan 2021 03:48:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJyklTC2+lrb+Bx87cFwY9zhEzV3xRjh09WybDPhMILJX+KsWfyLE2IeXkr5jgcDVBEZOItY X-Received: by 2002:aa7:cb8f:: with SMTP id r15mr1928583edt.130.1611229699418; Thu, 21 Jan 2021 03:48:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611229699; cv=none; d=google.com; s=arc-20160816; b=jY8hs5LIAM9op4eSM1obgzVuCrJFog+oVAuQkYVPOHLwAcVIBZU1gEctzbCs5lRW9U nYNkak0qMq0RgdUw+a8TKplBMK+tYAs6XZTz5lRq+5R6FHeno5TjX36zzD6byc2JDvxm 0BO8dOscdufJUyzJLclC7u1kYMr/0eLF+y1WCMGvH11yxVYFgWzmOyapnrgZCHTRCya1 L5VMjZszXR9MioLqwT1i4bFich0lRap/RYsufHzif3tdmNbileGWAoC5CUU+BwuyKzv5 XZlKribBe8+5FiFWU3wgNtyo2VFh3y4TuSn+1W52Qzm7aupSg41sXYwDB67d0x3IH6q8 bf0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:user-agent:references:in-reply-to :subject:cc:to:from:date:content-transfer-encoding:mime-version; bh=M/j0uUuJ3xqcRqSIViSdVFvq1BRviekGYtRrsJsMFHU=; b=mS1z0CyIbMVJoaVOAvyf3hv8aAyNfgeGpRCmZBrAWq5kRMChwEWMbv/2ritNIplKRX KsvPJlPjlHqBDG5JDS/QtRroElmotulgjBS9YkReTa1HrJPUDX4r1YacI3N3BLvhopoR Eal7KjJxXbgdfz5zXn32rswl/MC3pT+hXTfS9XZpJT/+TMMNj9IU8gmAuvEiczrsWDLE j1o51FQmepVcjT/t4i5WLiE74pioTudEQxUHyHDopVecwiDZ+6FfzpPZeKKyzZrV+S4V bXZ7nM4CcO/YecGHLRj6v8P1ZPwN3IRs0oYn/FO0TKEzMZBffTBfhqcNnvuO3uPwVtUq LDiQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m19si2047551edp.417.2021.01.21.03.47.55; Thu, 21 Jan 2021 03:48:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729951AbhAULqF (ORCPT + 99 others); Thu, 21 Jan 2021 06:46:05 -0500 Received: from mail.kernel.org ([198.145.29.99]:47640 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730453AbhAULpO (ORCPT ); Thu, 21 Jan 2021 06:45:14 -0500 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C629E238E3; Thu, 21 Jan 2021 11:44:25 +0000 (UTC) Received: from disco-boy.misterjones.org ([51.254.78.96] helo=www.loen.fr) by disco-boy.misterjones.org with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94) (envelope-from ) id 1l2YNz-009B6g-L6; Thu, 21 Jan 2021 11:44:23 +0000 MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Thu, 21 Jan 2021 11:44:23 +0000 From: Marc Zyngier To: Will Deacon Cc: Mohamed Mediouni , linux-arm-kernel@lists.infradead.org, Catalin Marinas , Mark Rutland , Hector Martin , linux-kernel@vger.kernel.org, Stan Skowronek Subject: Re: [RFC PATCH 3/7] arm64: mm: use nGnRnE instead of nGnRE on Apple processors In-Reply-To: <20210121112725.GA21750@willie-the-truck> References: <20210120132717.395873-1-mohamed.mediouni@caramail.com> <20210120132717.395873-4-mohamed.mediouni@caramail.com> <20210121112725.GA21750@willie-the-truck> User-Agent: Roundcube Webmail/1.4.10 Message-ID: X-Sender: maz@kernel.org X-SA-Exim-Connect-IP: 51.254.78.96 X-SA-Exim-Rcpt-To: will@kernel.org, mohamed.mediouni@caramail.com, linux-arm-kernel@lists.infradead.org, catalin.marinas@arm.com, mark.rutland@arm.com, marcan@marcan.st, linux-kernel@vger.kernel.org, stan@corellium.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-01-21 11:27, Will Deacon wrote: > On Wed, Jan 20, 2021 at 02:27:13PM +0100, Mohamed Mediouni wrote: >> Use nGnRnE instead of nGnRE on Apple SoCs to workaround a serious >> hardware quirk. >> >> On Apple processors, writes using the nGnRE device memory type get >> dropped in flight, >> getting to nowhere. >> >> Signed-off-by: Stan Skowronek >> Signed-off-by: Mohamed Mediouni >> --- >> arch/arm64/mm/proc.S | 26 ++++++++++++++++++++++++++ >> 1 file changed, 26 insertions(+) >> >> diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S >> index 1f7ee8c8b7b8..06436916f137 100644 >> --- a/arch/arm64/mm/proc.S >> +++ b/arch/arm64/mm/proc.S >> @@ -51,6 +51,25 @@ >> #define TCR_KASAN_HW_FLAGS 0 >> #endif >> >> +#ifdef CONFIG_ARCH_APPLE >> + >> +/* >> + * Apple cores appear to black-hole writes done with nGnRE. >> + * We settled on a work-around that uses MAIR vs changing every >> single user of >> + * nGnRE across the arm64 code. >> + */ >> + >> +#define MAIR_EL1_SET_APPLE \ >> + (MAIR_ATTRIDX(MAIR_ATTR_DEVICE_nGnRnE, MT_DEVICE_nGnRnE) | \ >> + MAIR_ATTRIDX(MAIR_ATTR_DEVICE_nGnRnE, MT_DEVICE_nGnRE) | \ >> + MAIR_ATTRIDX(MAIR_ATTR_DEVICE_GRE, MT_DEVICE_GRE) | \ >> + MAIR_ATTRIDX(MAIR_ATTR_NORMAL_NC, MT_NORMAL_NC) | \ >> + MAIR_ATTRIDX(MAIR_ATTR_NORMAL, MT_NORMAL) | \ >> + MAIR_ATTRIDX(MAIR_ATTR_NORMAL_WT, MT_NORMAL_WT) | \ >> + MAIR_ATTRIDX(MAIR_ATTR_NORMAL, MT_NORMAL_TAGGED)) >> + >> +#endif >> + >> /* >> * Default MAIR_EL1. MT_NORMAL_TAGGED is initially mapped as Normal >> memory and >> * changed during __cpu_setup to Normal Tagged if the system supports >> MTE. >> @@ -432,6 +451,13 @@ SYM_FUNC_START(__cpu_setup) >> * Memory region attributes >> */ >> mov_q x5, MAIR_EL1_SET >> +#ifdef CONFIG_ARCH_APPLE >> + mrs x0, MIDR_EL1 >> + lsr w0, w0, #24 >> + mov_q x1, MAIR_EL1_SET_APPLE >> + cmp x0, #0x61 // 0x61 = Implementer: Apple >> + csel x5, x1, x5, eq > > Why does this need to be done so early? It would be a lot cleaner if we > could detect this in a similar fashion to other errata and update the > MAIR > appropriately. If that's not possible because of early IO mappings > (which > ones?), then we could instead initialise to nGnRnE unconditionally, but > relax it to nGnRE if we detect that we _don't_ have the erratum. Would that imply another round-trip into the idmap, much like we do when we switch to non-global mappings? Or do you expect that we can change the MAIR with live mappings? M. -- Jazz is not dead. It just smells funny...