From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7BCDEC54E5D for ; Thu, 14 Mar 2024 19:07:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=/2ZVnB8RfmL4ez5GD749PfeiAq5BOW11c+vmWG4bhuc=; b=JOY8SKclTIZq5f 4IblqutjvE6dRKkHgU5w+hDGl5m2DNWvqoElHn+GJqG21qYkk9oGlK4TfP4uz0UHPPoR0RQVvCPsv i/rvPLlprBsajyp+R5efawT54Ua+Q6kbuLhEZ9y+wPiCBllfhnConk7gVlBcUSAZQgNi2PRQOMs/F 4kOLy0ha+fRI08lMJ9MchD/QEH8xx6ZBFWQEjZnGul+KrieCCtHb1W7BUWxfdXxTMFh9Cz5SDITuH 3PlXDbGZmgupx+iHNqwLki12daNWf3dm8n8hN/7tu0jk77BUKaQiGgDPxfBWwQt8yc78vasMae4Bg A35DOXZZ6P0MswKz0bNA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rkqPh-0000000FQtX-1jWn; Thu, 14 Mar 2024 19:06:49 +0000 Received: from fout4-smtp.messagingengine.com ([103.168.172.147]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rkqPd-0000000FQsl-2p8A for linux-arm-kernel@lists.infradead.org; Thu, 14 Mar 2024 19:06:47 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id EF3E513800C5; Thu, 14 Mar 2024 15:06:43 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Thu, 14 Mar 2024 15:06:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tyhicks.com; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1710443203; x=1710529603; bh=RCQmlGp3k6 bvYN0RNI3MYCaArrm2bXBnNGldMBKv0+M=; b=YLCJfRNw4qk13Tk78J9I9IIvgz rKpSA5JCPdGaFpSiMuOt6mw/mYgvhqQsvgDDWbTMa7LrZGxa2Wp5NWfu1cqJ31nL GNNGe+zOhA6IaVfKOE2DxwWusgnaU8jHP+IDzf3K8qx6+zTyXa3VEV4FyQxE5Mue 2x553yNefdBa+QG61GP0r+E6Z8R/WBuPTJoKxDPs9SXIG0olBBzueVSAxw/KQlPv pjUr4jhqSRxGirNbfGV+1itvpe8KpWxBTy2lBRJk0IFC8QDSkcNAZDbsnZEA3Bny +CbwragPCCtsQ5bz/CLXSum1zQ2gpxbiTv+VScgALJeUoI4AyzKWYLM8ElMg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1710443203; x=1710529603; bh=RCQmlGp3k6bvYN0RNI3MYCaArrm2 bXBnNGldMBKv0+M=; b=XG8uDL+ylScJRiGrCkiVidUj4YLfN+EQNZKm7bLCAnxG Vt+n8L8Th2tykaWeNv8xbaZiyyYEMf/DWv0EFzOiPaflx32XJjQm58S4XEt179MS bJvAViFIko7XxKv3unGw3BCr9+88IseWiN9/pdyymPtu1j6O2WGy8FVKtY7uj8j2 V0a6RpL/OG/8aU9b9ZZCySn0BXMyFD9+SV4z8D3XFZy7QjhmW3MpkVIFgUJ4bU/v QV9edp2cYZakyFIP0e+eRXTiE587rB1XJAODraG8p8yyGlfB44dCJRQEUaezii46 zrqUFkYhIhF99pCzORwXWbOh4D31Kf9nylDMVQp05g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrjeejgdduudekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepvfihlhgv rhcujfhitghkshcuoegtohguvgesthihhhhitghkshdrtghomheqnecuggftrfgrthhtvg hrnhepgfegkeeiffethefgteffudfhfeejhedvjefhjeekudelffdulefhfeekieeludej necuffhomhgrihhnpehkvghrnhgvlhdrohhrghenucevlhhushhtvghrufhiiigvpedtne curfgrrhgrmhepmhgrihhlfhhrohhmpegtohguvgesthihhhhitghkshdrtghomh X-ME-Proxy: Feedback-ID: i78e14604:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 14 Mar 2024 15:06:41 -0400 (EDT) Date: Thu, 14 Mar 2024 14:06:39 -0500 From: Tyler Hicks To: Will Deacon , Robin Murphy , Jason Gunthorpe , Jerry Snitselaar Cc: linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Dexuan Cui , Easwar Hariharan Subject: Re: Why is the ARM SMMU v1/v2 put into bypass mode on kexec? Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240314_120645_997348_3EC7D6F2 X-CRM114-Status: GOOD ( 19.22 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 2024-03-14 09:55:46, Tyler Hicks wrote: > Given that drivers are only optionally asked to implement the .shutdown > hook, which is required to properly quiesce devices before a kexec, why > is it that we put the ARM SMMU v1/v2 into bypass mode in the arm-smmu > driver's own .shutdown hook? > > arm_smmu_device_shutdown() -> set SMMU_sCR0.CLIENTPD bit to 1 > > Driver authors often forget to even implement a .shutdown hook, which > results in some hard-to-debug memory corruption issues in the kexec'ed > target kernel due to pending DMA operations happening on untranslated > addresses. Why not leave the SMMU in translate mode but clear the stream > mapping table (or maybe even call arm_smmu_device_reset()) in the SMMU's > .shutdown hook to prevent the memory corruption from happening in the > first place? > > Fully acknowledging that the proper fix is to quiesce the devices, I > feel like resetting the SMMU and leaving it in translate mode across > kexec would be more consistent with the intent behind v5.2 commit > 954a03be033c ("iommu/arm-smmu: Break insecure users by disabling bypass > by default"). The incoming transactions of devices, that weren't > properly quiesced during a kexec, would be blocked until their drivers > have a chance to reinitialize the devices in the new kernel. > > I appreciate any help understanding why bypass mode is utilized here as > I'm sure there are nuances that I haven't considered. Thank you! I now see that Will has previously mentioned that he'd be open to such a change: One thing I would be in favour of is changing the ->shutdown() code to honour disable_bypass=1 so that we put the SMMU in an aborting state instead of passthrough. Would that help at all? It would at least avoid the memory corruption on missing shutdown callback. - https://lore.kernel.org/linux-arm-kernel/20200608113852.GA3108@willie-the-truck/ Robin mentions the need to support kexec into a non-SMMU-aware OS. I hadn't considered that bit of complexity: ... consider if the first kernel *did* leave it enabled with whatever left-over translations in place, and kexec'ed into another OS that wasn't SMMU-aware... - https://lore.kernel.org/linux-arm-kernel/e072f61a-d6cf-2e34-efd5-c1db38c5c622@arm.com/ Now that we're 3-4 years removed from that conversation, has anything changed? Will, is there anything we'd need to watch out for if we were to prototype this sort of change? For example, would it be wise to disable fault interrupts when putting the SMMU in an aborting state before kexec'ing? Thanks again! Tyler _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel