Received: by 2002:a9a:4c47:0:b029:116:c383:538 with SMTP id u7csp7546342lko; Fri, 30 Jul 2021 06:12:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxaRdU7twXrNsAUvIt2tdz/u2JrMMMkQfL5u6ImwdPutFHjT+KcmeX0aVqev95IkaN/Z9QP X-Received: by 2002:a05:6e02:154b:: with SMTP id j11mr1859561ilu.96.1627650740248; Fri, 30 Jul 2021 06:12:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627650740; cv=none; d=google.com; s=arc-20160816; b=AUBNX+1L7jfFETrEiBV9yaaOgGe2chr6LvyTVHeZ5j6CegsZ/PBYCXt2z57LDcHtDR MBwTc3yyvv1rRMenFFi32HWFnnBYP/JTwCl9Q3kOWzvypVMahbtBcen5NSv/wv9zyNAG HOYqVl57JEfJjTAKiLt2tqqKGr3t/KGGUr9ubWBYasrz++3aRfDs93eRq4nquikHwmwh r1vWUYn7xdQ6IefP4W6mC5tC5yuQeCUzM4M4DRestcYwkRg/G0sprd5WqvouI00Suum+ WAdGLt1TvwhvzxfYUXYXgEnAI+43YHOrfjHWyu3Nmfayq/MCON5/w6/Z2sxHBTvZHjPB W9Jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=M6pOuP0tBAIjUNybaCRPowoY6hxKoBrfa8xIqBog3aY=; b=uikamLiNXDfppoBrgy0BWWKZIJxWYoVOBQEw7EfxTonVY/uQ9JnxUceJNMw7w4nYIq xgGS3BAxhsg4ESKtHa+1dRUZM18yvM3fI1oEODj8LsBnxnhCMAGKdW1CMd/LPcRYIv4k 2jnoFh9u8V9lUBzboPDrr13RPCtbwyxzvHfmPpnXKCnIwZVFj+TwuetWHW51aWhwgBDP c8ZQN2Fa1jpSiPyIO+Pnha3PLgLU3qEBbZttw+iNFvvyY6O1T1y5VQEj1zq1EpBzuapR rlaw0aDj4YxY1gW8jDbJ05aDsGwuMwQ7BO0rNSjJwr0BU/le+72bLVDD3Wfx1Wu0KDxL UO6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YRmmKBxn; 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 h17si1542353jav.110.2021.07.30.06.12.08; Fri, 30 Jul 2021 06:12:20 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YRmmKBxn; 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 S238912AbhG3NLP (ORCPT + 99 others); Fri, 30 Jul 2021 09:11:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:60944 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238893AbhG3NLN (ORCPT ); Fri, 30 Jul 2021 09:11:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id AFDF760462; Fri, 30 Jul 2021 13:11:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1627650668; bh=dCPVqim+3QLsfYnttxB0ASgmRObsONjZkZ9VkM4UMZA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=YRmmKBxntTjK6srQwnni3UZ1ku7RqG9OCZSgjIgPkKxdxzbKcEHnjt5qO++TlplUW bHNVzY6wzSMTntl5eF+8RU7L32sdKysWQfa+UCGrzlf0PKDKmsfHrdn26DiQVyJmfP +GyoQSuIuIgCuG+zUi5lJb97/6wYrh94i/+Vy2SR8ZMsnzvXGWZJOh14jQYNgMzGnR X0+oF97+vle8eTXlYuW4uw7VFzE21pHS8AcU+FtEqoD/ivoz5m4T1riIgHaUr+v5eF FbxXGurZZJEGmNg3ZXivybbt+XAoKlM1hKHXIhfCqbYoQSmrPqPtN4n+/L0rKzCKE8 fFT+yqgfRfiyQ== Date: Fri, 30 Jul 2021 14:11:03 +0100 From: Will Deacon To: Marc Zyngier 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 07/16] KVM: arm64: Wire MMIO guard hypercalls Message-ID: <20210730131103.GD23756@willie-the-truck> References: <20210715163159.1480168-1-maz@kernel.org> <20210715163159.1480168-8-maz@kernel.org> <20210727181145.GF19173@willie-the-truck> <87v94ud8av.wl-maz@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87v94ud8av.wl-maz@kernel.org> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 28, 2021 at 11:47:20AM +0100, Marc Zyngier wrote: > On Tue, 27 Jul 2021 19:11:46 +0100, > Will Deacon wrote: > > > > On Thu, Jul 15, 2021 at 05:31:50PM +0100, Marc Zyngier wrote: > > > Plumb in the hypercall interface to allow a guest to discover, > > > enroll, map and unmap MMIO regions. > > > > > > Signed-off-by: Marc Zyngier > > > --- > > > arch/arm64/kvm/hypercalls.c | 20 ++++++++++++++++++++ > > > include/linux/arm-smccc.h | 28 ++++++++++++++++++++++++++++ > > > 2 files changed, 48 insertions(+) > > > > > > diff --git a/arch/arm64/kvm/hypercalls.c b/arch/arm64/kvm/hypercalls.c > > > index 30da78f72b3b..a3deeb907fdd 100644 > > > --- a/arch/arm64/kvm/hypercalls.c > > > +++ b/arch/arm64/kvm/hypercalls.c > > > @@ -5,6 +5,7 @@ > > > #include > > > > > > #include > > > +#include > > > > > > #include > > > #include > > > @@ -129,10 +130,29 @@ int kvm_hvc_call_handler(struct kvm_vcpu *vcpu) > > > case ARM_SMCCC_VENDOR_HYP_KVM_FEATURES_FUNC_ID: > > > val[0] = BIT(ARM_SMCCC_KVM_FUNC_FEATURES); > > > val[0] |= BIT(ARM_SMCCC_KVM_FUNC_PTP); > > > + val[0] |= BIT(ARM_SMCCC_KVM_FUNC_MMIO_GUARD_INFO); > > > + val[0] |= BIT(ARM_SMCCC_KVM_FUNC_MMIO_GUARD_ENROLL); > > > + val[0] |= BIT(ARM_SMCCC_KVM_FUNC_MMIO_GUARD_MAP); > > > + val[0] |= BIT(ARM_SMCCC_KVM_FUNC_MMIO_GUARD_UNMAP); > > > break; > > > case ARM_SMCCC_VENDOR_HYP_KVM_PTP_FUNC_ID: > > > kvm_ptp_get_time(vcpu, val); > > > break; > > > + case ARM_SMCCC_VENDOR_HYP_KVM_MMIO_GUARD_INFO_FUNC_ID: > > > + val[0] = PAGE_SIZE; > > > + break; > > > > I get the nagging feeling that querying the stage-2 page-size outside of > > MMIO guard is going to be useful once we start looking at memory sharing, > > so perhaps rename this to something more generic? > > At this stage, why not follow the architecture and simply expose it as > ID_AA64MMFR0_EL1.TGran{4,64,16}_2? That's exactly what it is for, and > we already check for this in KVM itself. Nice, I hadn't thought of that. On reflection, though, I don't agree that it's "exactly what it is for" -- the ID register talks about the supported stage-2 page-sizes, whereas we want to advertise the one page size that we're currently using. In other words, it's important that we only ever populate one of the fields and I wonder if that could bite us in future somehow? Up to you, you've definitely got a better feel for this than me. > > > + case ARM_SMCCC_VENDOR_HYP_KVM_MMIO_GUARD_ENROLL_FUNC_ID: > > > + set_bit(KVM_ARCH_FLAG_MMIO_GUARD, &vcpu->kvm->arch.flags); > > > + val[0] = SMCCC_RET_SUCCESS; > > > + break; > > > + case ARM_SMCCC_VENDOR_HYP_KVM_MMIO_GUARD_MAP_FUNC_ID: > > > + if (kvm_install_ioguard_page(vcpu, vcpu_get_reg(vcpu, 1))) > > > + val[0] = SMCCC_RET_SUCCESS; > > > + break; > > > + case ARM_SMCCC_VENDOR_HYP_KVM_MMIO_GUARD_UNMAP_FUNC_ID: > > > + if (kvm_remove_ioguard_page(vcpu, vcpu_get_reg(vcpu, 1))) > > > + val[0] = SMCCC_RET_SUCCESS; > > > + break; > > > > I think there's a slight discrepancy between MAP and UNMAP here in that > > calling UNMAP on something that hasn't been mapped will fail, whereas > > calling MAP on something that's already been mapped will succeed. I think > > that might mean you can't reason about the final state of the page if two > > vCPUs race to call these functions in some cases (and both succeed). > > I'm not sure that's the expected behaviour for ioremap(), for example > (you can ioremap two portions of the same page successfully). Hmm, good point. Does that mean we should be refcounting the stage-2? Otherwise if we do something like: foo = ioremap(page, 0x100); bar = ioremap(page+0x100, 0x100); iounmap(foo); then bar will break. Or did I miss something in the series? Will