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 F057DC4332F for ; Wed, 21 Dec 2022 18:38:53 +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=IOeGEjKYy/1jarXurtfJQWxk7kJwTfCTAHtdSRqwjjM=; b=0x45S4oesLg3Tw ACcexRcanmNPcOYMINgpktC4v/eSYblMTgXRudGabe/LS7fen6LHb1csOofGxIv6+mC5Crt8n1od6 Qh5CZVCTAZWeGJnMgJoayzTPWQrRZKgOSYavLc6u9uYjY009zRZK3V43Z1sDH3bn/q194KdBkCEkz f4Pd/frVXLjotOSGOXT/nbW6W6Ohetpi836d4P4sNCa2VJrxt6SX1YMA3fDLaizibfey91Gop+p8p W+Fa06yu5n8YXMrBxap4HlpfAfXg992A9BJ9HE9XOyMpk8iUEV30v+3UsbATy/H6CWY17E3Ljxx2E a8HTaGJ2N/Q5m9JgBD0A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p83y1-000dzh-88; Wed, 21 Dec 2022 18:37:26 +0000 Received: from out-23.mta0.migadu.com ([91.218.175.23]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1p83ny-000YLO-0W for linux-arm-kernel@lists.infradead.org; Wed, 21 Dec 2022 18:27:04 +0000 Date: Wed, 21 Dec 2022 18:26:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1671647212; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=oCiAxJiKxcSU5UorQx7uMbenKIARcOlfI4FuMp6UPQI=; b=XYkz2RtIvG63Ms5qZ0nHvVbllVtrnrqKun6b7hlGxdceeiZSsaJ6GT9MGFJZReWHwcRqtV Hj7s/l4rLk+Ahr4+sh5zi7jaq0HCx4nbkWXoWOeGfJMfVraw6WQUGERd2oUWtkIN7jxxJp ZY+b0NUaxImbzey19b2CT36oAshvQ04= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Marc Zyngier 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 Message-ID: References: <20221220200923.1532710-1-maz@kernel.org> <20221220200923.1532710-2-maz@kernel.org> <86pmcdaylx.wl-maz@kernel.org> <86k02kbq2x.wl-maz@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <86k02kbq2x.wl-maz@kernel.org> X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221221_102702_283072_44B3C1AD X-CRM114-Status: GOOD ( 37.10 ) 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 Wed, Dec 21, 2022 at 05:53:58PM +0000, Marc Zyngier wrote: > 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? Looks good to me, thanks! Reviewed-by: Oliver Upton > 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 > --------------------- -- Best, Oliver _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel