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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44609C41535 for ; Wed, 21 Dec 2022 17:54:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230462AbiLURyH (ORCPT ); Wed, 21 Dec 2022 12:54:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229491AbiLURyF (ORCPT ); Wed, 21 Dec 2022 12:54:05 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDC4223176; Wed, 21 Dec 2022 09:54:03 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 79052B81BDD; Wed, 21 Dec 2022 17:54:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 30AEDC433EF; Wed, 21 Dec 2022 17:54:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1671645241; bh=7LRl7Za1xJWk+DAkT1K7niH/xhQTNQuhVESv5AviT0Q=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=MwcYMmy0zWFWpAtAluvPnPFo8TnCkeieBXd6A2rvAkrB+3oz764XK7wH8x6tQLkfA bqlk63bzyNJbb9HqEr5o3MV5C8brm3/L4hakACfnJhjiHw+vxoeRkj7yUyYBUNymi0 rvLZn1kvb10ovCLU+8p0LPxcWSMnGJ/iTezD7Z5uM/Ci0HJg06RKMNU3f49k1NCDm6 1AhpDpNqy/AcbCCcAhjzKewk+wy5+yKHnEBjeO/sCLrgyFZz1n1TivKmZ/jWpi7O8u 7LE/dzcHHjAp82elLTpCdMSSyUeQgviJMv8nsEjsH3AGtxIEtczGdASqdQ4xSIxvkD edbO2ZlXSgNSQ== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1p83Hy-00ECiH-OR; Wed, 21 Dec 2022 17:53:58 +0000 Date: Wed, 21 Dec 2022 17:53:58 +0000 Message-ID: <86k02kbq2x.wl-maz@kernel.org> From: Marc Zyngier To: Oliver Upton Cc: kvmarm@lists.cs.columbia.edu, kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, James Morse , Suzuki K Poulose , Alexandru Elisei , Ard Biesheuvel , Will Deacon , Quentin Perret , stable@vger.kernel.org Subject: Re: [PATCH 1/3] KVM: arm64: Fix S1PTW handling on RO memslots In-Reply-To: References: <20221220200923.1532710-1-maz@kernel.org> <20221220200923.1532710-2-maz@kernel.org> <86pmcdaylx.wl-maz@kernel.org> 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/28.2 (aarch64-unknown-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: oliver.upton@linux.dev, kvmarm@lists.cs.columbia.edu, kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, james.morse@arm.com, suzuki.poulose@arm.com, alexandru.elisei@arm.com, ardb@kernel.org, will@kernel.org, qperret@google.com, stable@vger.kernel.org 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: kvm@vger.kernel.org On Wed, 21 Dec 2022 16:50:30 +0000, Oliver Upton wrote: > > On Wed, Dec 21, 2022 at 09:35:06AM +0000, Marc Zyngier wrote: > > [...] > > > > > + if (kvm_vcpu_abt_iss1tw(vcpu)) { > > > > + /* > > > > + * Only a permission fault on a S1PTW should be > > > > + * considered as a write. Otherwise, page tables baked > > > > + * in a read-only memslot will result in an exception > > > > + * being delivered in the guest. > > > > > > Somewhat of a tangent, but: > > > > > > Aren't we somewhat unaligned with the KVM UAPI by injecting an > > > exception in this case? I know we've been doing it for a while, but it > > > flies in the face of the rules outlined in the > > > KVM_SET_USER_MEMORY_REGION documentation. > > > > That's an interesting point, and I certainly haven't considered that > > for faults introduced by page table walks. > > > > I'm not sure what userspace can do with that though. The problem is > > that this is a write for which we don't have useful data: although we > > know it is a page-table walker access, we don't know what it was about > > to write. The instruction that caused the write is meaningless (it > > could either be a load, a store, or an instruction fetch). How do you > > populate the data[] field then? > > > > If anything, this is closer to KVM_EXIT_ARM_NISV, for which we give > > userspace the full ESR and ask it to sort it out. I doubt it will be > > able to, but hey, maybe it is worth a shot. This would need to be a > > different exit reason though, as NISV is explicitly for non-memslot > > stuff. > > > > In any case, the documentation for KVM_SET_USER_MEMORY_REGION needs to > > reflect the fact that KVM_EXIT_MMIO cannot represent a fault due to a > > S1 PTW. > > Oh I completely agree with you here. I probably should have said before, > I think the exit would be useless anyway. Getting the documentation in > line with the intended behavior seems to be the best fix. Right. How about something like this? diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index 226b40baffb8..72abd018a618 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -1381,6 +1381,14 @@ It is recommended to use this API instead of the KVM_SET_MEMORY_REGION ioctl. The KVM_SET_MEMORY_REGION does not allow fine grained control over memory allocation and is deprecated. +Note: On arm64, a write generated by the page-table walker (to update +the Access and Dirty flags, for example) never results in a +KVM_EXIT_MMIO exit when the slot has the KVM_MEM_READONLY flag. This +is because KVM cannot provide the data that would be written by the +page-table walker, making it impossible to emulate the access. +Instead, an abort (data abort if the cause of the page-table update +was a load or a store, instruction abort if it was an instruction +fetch) is injected in the guest. 4.36 KVM_SET_TSS_ADDR --------------------- Thanks, M. -- Without deviation from the norm, progress is not possible.