Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1169034pxb; Thu, 4 Feb 2021 06:44:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJwgwPbhVsXUsTTHhTZ6fOdkI7hW+wG7muZhDaugtnXbEWF7xCaYvu9kj5BODWrA4OCUj7zL X-Received: by 2002:a17:906:c049:: with SMTP id bm9mr7930661ejb.535.1612449883813; Thu, 04 Feb 2021 06:44:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612449883; cv=none; d=google.com; s=arc-20160816; b=0Ed/6nXto6zE4ey6rEvk5GSU+qE2t+WLEDKpeJ9SGhURPC9RQKG/rVNRqbr4DGd0mW Qo8tpOM2lwwYRypttY0AkSBBhii65D0YYtmm2HvtAOWEaIwVubUEJVdLzbTQFvUqoTX8 iULWS54+ZxNf5GCzgcWFyEjB9COp8a0R0KLDbzGuYGmo3dWnQ/JHxOCEe5AX/b7H9jMd mqIAdTzSfUHgOBbIGGS5Yfnws4JsEhXpGdjG71ztJi1n/S3TGv3ES3OKcsj8T22DlUBw 6e9FqiyrPQ32Df0tgNpwKdMhtWusH0sVS/eBUdVUCRP6HLUAImKEYMeNLKP0A2yVTmdl T2wg== 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=mYxtadtUdjFc2/M8EDrhWV5f12Qab2FX0OxdcUWKr7Q=; b=Jl+W4qA0j+pQcDK8UOBnQgRJRvQqDcCQjeJoRy1igC6IgbnuCJyLVLx8HRy9PoA8NU tdn0aWbH6t1Tlsa0SE3Eg+TZVO41RK4x52Mr9G4ZGi7uaiAxYnJv5cBb7UCl+VsHhwUU t+N7J+i4vSPmz654Igu3PJe+rWB3+1ktwebFqa0iVT2CYtfG19E7XbRw57AMehdW39OB 54dEdG4eUUMq+nn3h+Gd66qQogJ4Z5wwRwcfz59GuORUAD80dtgF7XrGEQP8Orf+1mCP 5Macw0llHrR4s1rWqR/vAtOjlqt7V8X87xKHlzZTxjwVTytiOSDHCnwYYgTBx0h96I4A lEiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lFUg2MhC; 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 z24si2780343edl.286.2021.02.04.06.44.18; Thu, 04 Feb 2021 06:44:43 -0800 (PST) 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=lFUg2MhC; 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 S236805AbhBDOle (ORCPT + 99 others); Thu, 4 Feb 2021 09:41:34 -0500 Received: from mail.kernel.org ([198.145.29.99]:40470 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236850AbhBDOiN (ORCPT ); Thu, 4 Feb 2021 09:38:13 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 96D7A64F42; Thu, 4 Feb 2021 14:37:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612449452; bh=eX/1xnMdBH58oq4Cm//d2eH7lZEj/ruuIIGGb0auhuU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=lFUg2MhCGRwGCnWckleg2a585Xz+UPVroJoNasl+l4uT0swGpvGoFDX9tZU3lQU8T /yrQSfPWtuDwynUHzXjcNMRmcL3Hpe9GUojzRx7oLBzcEMnuf5Fugs46AmSYNirHm0 GOMjZtv2zt6lmt5JUCXfTx3Ou8ZLooidFTn5ePcH+jLvp6JlcZ/wq3kED3EeiOTmV8 JEyrlU6Zy1/rze1wxKk2PST5LR1xrcY/gBK6mtU2kGkZssp+m9Yz6Ihgp+3PZWtUtX O386OeZwIL5OOsEzKkiZf9BK0SHUN10bysPQh3rGOM9NhwGiYRKNzb5RJWkLPFQzp3 CLQa41rKVOCfA== Date: Thu, 4 Feb 2021 14:37:26 +0000 From: Will Deacon To: Quentin Perret Cc: Catalin Marinas , Marc Zyngier , James Morse , Julien Thierry , Suzuki K Poulose , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, android-kvm@google.com, linux-kernel@vger.kernel.org, kernel-team@android.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, Fuad Tabba , Mark Rutland , David Brazdil Subject: Re: [RFC PATCH v2 26/26] KVM: arm64: Wrap the host with a stage 2 Message-ID: <20210204143725.GB20815@willie-the-truck> References: <20210108121524.656872-1-qperret@google.com> <20210108121524.656872-27-qperret@google.com> <20210203161146.GJ18974@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 04, 2021 at 02:26:35PM +0000, Quentin Perret wrote: > On Wednesday 03 Feb 2021 at 16:11:47 (+0000), Will Deacon wrote: > > On Fri, Jan 08, 2021 at 12:15:24PM +0000, Quentin Perret wrote: > > > When KVM runs in protected nVHE mode, make use of a stage 2 page-table > > > to give the hypervisor some control over the host memory accesses. At > > > the moment all memory aborts from the host will be instantly idmapped > > > RWX at stage 2 in a lazy fashion. Later patches will make use of that > > > infrastructure to implement access control restrictions to e.g. protect > > > guest memory from the host. > > > > > > Signed-off-by: Quentin Perret > > > --- > > > arch/arm64/include/asm/kvm_cpufeature.h | 2 + > > > arch/arm64/kernel/image-vars.h | 3 + > > > arch/arm64/kvm/hyp/include/nvhe/mem_protect.h | 33 +++ > > > arch/arm64/kvm/hyp/nvhe/Makefile | 2 +- > > > arch/arm64/kvm/hyp/nvhe/hyp-init.S | 1 + > > > arch/arm64/kvm/hyp/nvhe/hyp-main.c | 6 + > > > arch/arm64/kvm/hyp/nvhe/mem_protect.c | 191 ++++++++++++++++++ > > > arch/arm64/kvm/hyp/nvhe/setup.c | 6 + > > > arch/arm64/kvm/hyp/nvhe/switch.c | 7 +- > > > arch/arm64/kvm/hyp/nvhe/tlb.c | 4 +- > > > 10 files changed, 248 insertions(+), 7 deletions(-) > > > create mode 100644 arch/arm64/kvm/hyp/include/nvhe/mem_protect.h > > > create mode 100644 arch/arm64/kvm/hyp/nvhe/mem_protect.c > > > > [...] > > > > > +void handle_host_mem_abort(struct kvm_cpu_context *host_ctxt) > > > +{ > > > + enum kvm_pgtable_prot prot; > > > + u64 far, hpfar, esr, ipa; > > > + int ret; > > > + > > > + esr = read_sysreg_el2(SYS_ESR); > > > + if (!__get_fault_info(esr, &far, &hpfar)) > > > + hyp_panic(); > > > + > > > + prot = KVM_PGTABLE_PROT_R | KVM_PGTABLE_PROT_W | KVM_PGTABLE_PROT_X; > > > + ipa = (hpfar & HPFAR_MASK) << 8; > > > + ret = host_stage2_map(ipa, PAGE_SIZE, prot); > > > > Can we try to put down a block mapping if the whole thing falls within > > memory? > > Yes we can! And in fact we can do that outside of memory too. It's > queued for v3 already, so stay tuned ... :) Awesome! The Stage-2 TLB thanks you. Will