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 X-Spam-Level: X-Spam-Status: No, score=-4.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46B7CC433DB for ; Fri, 12 Feb 2021 18:19:17 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E536564E8E for ; Fri, 12 Feb 2021 18:19:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E536564E8E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Type: Content-Transfer-Encoding:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Message-ID:References:In-Reply-To:Subject:To:From: Date:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=FBEQZbGK1x+JB+wHMSYjoW0gfLg99RrcNUztxJvXrlk=; b=C+Y4NwuDDuCI7XNZR0zoRybP0 atCG6RLDIFkzuULwZ1bXs4CT/Tulr6S71n39p/6eXjzeFtr8AQIDa9ZFh4H+TEAGB9wx7xhp0wVW9 z4hkxDUS0B6xCk+Vkb2RvoGZmueeQWGOaK0DV025MttH7Rxj3CwtoO+zLZWunTWWFR/fR0hKzVqNO ZbJ/ZtdveW7BYvQQhUc31uhr6yrGlnaJ6YLfw3uCUajBcd13WChdJx411TQksYDhsO9ber4YRUWcV siT1AJ07UjufqmwV63YczZbrCqcW/KnozqWtnr0wsRYs7HetL+ryq13DGVYRbWnPwvWXsvSPz+yue m+bs3+QMQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lAd19-00068i-Bo; Fri, 12 Feb 2021 18:18:11 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1lAd15-00067L-Va for linux-arm-kernel@lists.infradead.org; Fri, 12 Feb 2021 18:18:09 +0000 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 BFB7D64DDF; Fri, 12 Feb 2021 18:18:06 +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 1lAd12-00Dsau-MJ; Fri, 12 Feb 2021 18:18:04 +0000 MIME-Version: 1.0 Date: Fri, 12 Feb 2021 18:18:04 +0000 From: Marc Zyngier To: Alexandru Elisei Subject: Re: [PATCH] KVM: arm64: Handle CMOs on Read Only memslots In-Reply-To: <4bfd380b-a654-c104-f424-a258bb142e34@arm.com> References: <20210211142738.1478292-1-maz@kernel.org> <4bfd380b-a654-c104-f424-a258bb142e34@arm.com> User-Agent: Roundcube Webmail/1.4.10 Message-ID: <6c127a2d4276b56205d2d28cc0b9ffc2@kernel.org> X-Sender: maz@kernel.org X-SA-Exim-Connect-IP: 51.254.78.96 X-SA-Exim-Rcpt-To: alexandru.elisei@arm.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com, will@kernel.org, kernel-team@android.com, jianyong.wu@arm.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210212_131808_769272_5310212F X-CRM114-Status: GOOD ( 25.53 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, Suzuki K Poulose , kernel-team@android.com, Jianyong Wu , James Morse , linux-arm-kernel@lists.infradead.org, Will Deacon , kvmarm@lists.cs.columbia.edu, Julien Thierry Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Alex, On 2021-02-12 17:12, Alexandru Elisei wrote: > Hi Marc, > > I've been trying to get my head around what the architecture says about > CMOs, so > please bare with me if I misunderstood some things. No worries. I've had this patch for a few weeks now, and can't make up my mind about it. It does address an actual issue though, so I couldn't just discard it... ;-) > On 2/11/21 2:27 PM, Marc Zyngier wrote: >> It appears that when a guest traps into KVM because it is >> performing a CMO on a Read Only memslot, our handling of >> this operation is "slightly suboptimal", as we treat it as >> an MMIO access without a valid syndrome. >> >> The chances that userspace is adequately equiped to deal >> with such an exception being slim, it would be better to >> handle it in the kernel. >> >> What we need to provide is roughly as follows: >> >> (a) if a CMO hits writeable memory, handle it as a normal memory acess >> (b) if a CMO hits non-memory, skip it >> (c) if a CMO hits R/O memory, that's where things become fun: >> (1) if the CMO is DC IVAC, the architecture says this should result >> in a permission fault >> (2) if the CMO is DC CIVAC, it should work similarly to (a) > > When you say it should work similarly to (a), you mean it should be > handled as a > normal memory access, without the "CMO hits writeable memory" part, > right? What I mean is that the cache invalidation should take place, preferably without involving KVM at all (other than populating S2 if required). > >> >> We already perform (a) and (b) correctly, but (c) is a total mess. >> Hence we need to distinguish between IVAC (c.1) and CIVAC (c.2). >> >> One way to do it is to treat CMOs generating a translation fault as >> a *read*, even when they are on a RW memslot. This allows us to >> further triage things: >> >> If they come back with a permission fault, that is because this is >> a DC IVAC instruction: >> - inside a RW memslot: no problem, treat it as a write (a)(c.2) >> - inside a RO memslot: inject a data abort in the guest (c.1) >> >> The only drawback is that DC IVAC on a yet unmapped page faults >> twice: one for the initial translation fault that result in a RO >> mapping, and once for the permission fault. I think we can live with >> that. > > I'm trying to make sure I understand what the problem is. > > gfn_to_pfn_prot() returnsKVM_HVA_ERR_RO_BAD if the write is to a RO > memslot. > KVM_HVA_ERR_RO_BAD is PAGE_OFFSET + PAGE_SIZE, which means that > is_error_noslot_pfn() return true. In that case we exit to userspace > with -EFAULT > for DC IVAC and DC CIVAC. But what we should be doing is this: > > - For DC IVAC, inject a dabt with ISS = 0x10, meaning an external abort > (that's > what kvm_inject_dabt_does()). > > - For DC CIVAC, exit to userspace with -EFAULT. > > Did I get that right? Not quite. What I *think* we should do is: - DC CIVAC should just work, without going to userspace. I can't imagine a reason why we'd involve userspace for this, and we currently don't really have a good way to describe this to userspace. - DC IVAC is more nuanced: we could either inject an exception (which is what this patch does), or perform the CMO ourselves as a DC CIVAC (consistent with the IVA->CIVA upgrade caused by having a S2 translation). This second approach is comparable to what we do when the guest issues a CMO on an emulated MMIO address (we don't inject a fault). Thanks, M. -- Jazz is not dead. It just smells funny... _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel