Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5132567pxv; Wed, 28 Jul 2021 04:03:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0uTdn7ESSHFEM7rsnHoa7z4zvDO9ffPmUown28fS+dU1dnEoBrlpncxwR3K9saKWMyp8o X-Received: by 2002:a5e:9747:: with SMTP id h7mr13405849ioq.92.1627470221697; Wed, 28 Jul 2021 04:03:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627470221; cv=none; d=google.com; s=arc-20160816; b=QV4R/6EmGQUQxWkrEXYvmk3AYMn0wA4FmaH2PwK057t5bPmM1YszF7o3RPMTVvLHdl FLYzxKdsRnRzvXsdQfuOtRmpk0fk6ZtQwYxvBDRHeCamKVDWTu2qOJzfIyI5125AN2EY juK7Uk5MAVf1rSd6cS5DMzt1t+FmDqfQ5Me08ggcYpE2sXQO/Sy2aubUMUepBKb8apBF ZocG+uRbE1cVtBU+pYDETFlrFnATAXUfTH4bk7DnGVPshUQieNjROk86q34KQQgRqPB9 fBdHqYlxijblOnOYAoFmlOoSXq47QYqBq1O3TuP4XicLuJiHxs7Mf4M0krMWNFqE+xBy VLsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date; bh=5BmvSNqdAqS8alddP8X2bHc7Mw/T7bY0p2hFvTkdlyw=; b=Kg3axZ4m1WxlZDiYMuY7RFelNlO00qLcplwmQyZJGykAHj1LK/a4U+VBu2NWKyjBXg Ry2lM/Bkl3mJY4NI7LfVYG/d+0y1p0alZT3D07KHD70bLsDEFlUKE4c2/JWlmJNoJ0Uy FGH4BZTOJsW1aG48ORHiUNr7hyVpHzlbpBnACjoHlPt0jV4jq0Q/ErrWodf4IMg3XOhz joa48VQrCDOZsQJL/bxCvQQ8b6D3kKGV+Ldz9ptc+tVaziiWlBdHyLGLjPwxClN04zYp 1Zoo7x5QhdkoyyGdkRtjdh85mX1ccXMfvKfkWuk43EGHs7O+IMVdqZVDa0sWZ1MqcUhI uyGQ== 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 e20si7957633iow.6.2021.07.28.04.03.30; Wed, 28 Jul 2021 04:03:41 -0700 (PDT) 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 S236027AbhG1LCE (ORCPT + 99 others); Wed, 28 Jul 2021 07:02:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:57230 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234181AbhG1LB4 (ORCPT ); Wed, 28 Jul 2021 07:01:56 -0400 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 AEBEA60F46; Wed, 28 Jul 2021 11:01:55 +0000 (UTC) Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1m8hJx-001Vuk-R3; Wed, 28 Jul 2021 12:01:53 +0100 Date: Wed, 28 Jul 2021 12:01:53 +0100 Message-ID: <87tuked7mm.wl-maz@kernel.org> From: Marc Zyngier To: Will Deacon Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, qperret@google.com, dbrazdil@google.com, Srivatsa Vaddagiri , Shanker R Donthineni , James Morse , Suzuki K Poulose , Alexandru Elisei , kernel-team@android.com Subject: Re: [PATCH 12/16] mm/ioremap: Add arch-specific callbacks on ioremap/iounmap calls In-Reply-To: <20210727181203.GG19173@willie-the-truck> References: <20210715163159.1480168-1-maz@kernel.org> <20210715163159.1480168-13-maz@kernel.org> <20210727181203.GG19173@willie-the-truck> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: will@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, qperret@google.com, dbrazdil@google.com, vatsa@codeaurora.org, sdonthineni@nvidia.com, james.morse@arm.com, suzuki.poulose@arm.com, alexandru.elisei@arm.com, kernel-team@android.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 Tue, 27 Jul 2021 19:12:04 +0100, Will Deacon wrote: > > On Thu, Jul 15, 2021 at 05:31:55PM +0100, Marc Zyngier wrote: > > Add a pair of hooks (ioremap_page_range_hook/iounmap_page_range_hook) > > that can be implemented by an architecture. > > > > Signed-off-by: Marc Zyngier > > --- > > include/linux/io.h | 3 +++ > > mm/ioremap.c | 13 ++++++++++++- > > mm/vmalloc.c | 8 ++++++++ > > 3 files changed, 23 insertions(+), 1 deletion(-) > > > > diff --git a/include/linux/io.h b/include/linux/io.h > > index 9595151d800d..0ffc265f114c 100644 > > --- a/include/linux/io.h > > +++ b/include/linux/io.h > > @@ -21,6 +21,9 @@ void __ioread32_copy(void *to, const void __iomem *from, size_t count); > > void __iowrite64_copy(void __iomem *to, const void *from, size_t count); > > > > #ifdef CONFIG_MMU > > +void ioremap_page_range_hook(unsigned long addr, unsigned long end, > > + phys_addr_t phys_addr, pgprot_t prot); > > +void iounmap_page_range_hook(phys_addr_t phys_addr, size_t size); > > int ioremap_page_range(unsigned long addr, unsigned long end, > > phys_addr_t phys_addr, pgprot_t prot); > > #else > > Can we avoid these hooks by instead not registering the regions proactively > in the guest and moving that logic to a fault handler which runs off the > back of the injected data abort? From there, we could check if the faulting > IPA is a memory address and register it as MMIO if not. > > Dunno, you've spent more time than me thinking about this, but just > wondering if you'd had a crack at doing it that way, as it _seems_ simpler > to my naive brain. I thought about it, but couldn't work out whether it was always possible for the guest to handle these faults (first access in an interrupt context, for example?). Also, this changes the semantics of the protection this is supposed to offer: any access out of the RAM space will generate an abort, and the fault handler will grant MMIO forwarding for this page. Stray accesses that would normally be properly handled as fatal would now succeed and be forwarded to userspace, even if there was no emulated devices there. For this to work, we'd need to work out whether there is any existing device mapping that actually points to this page. And whether it actually is supposed to be forwarded to userspace. Do we have a rmap for device mappings? M. -- Without deviation from the norm, progress is not possible.