From patchwork Tue Oct 19 12:13:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 12569759 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68CDAC433EF for ; Tue, 19 Oct 2021 12:22:59 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 35B2861260 for ; Tue, 19 Oct 2021 12:22:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 35B2861260 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=WNVFwsZQicZ1LGKU7fcLr7xK8lEeYcSF6yh1NqE3Ksg=; b=rEMDt4lU6ucSihxYhL9Hpnb8oW nMhKBS/O7ooaCAWOGL/Ex7J3JCQViStkSoEnl1WXseoelzs99UF9eVGI7ZU5B3Giuj379KZO4NOgG 3W/axq9y+gjwM5ZllOK+xH1riSZm0YMjCJ+f8J4IW3YIgP5h0IzcYxl8YMk4NED7Ihyv0FuoBOiEz ZuW/UgLOpbt2wRxAgdqgfP29fy1Jn2+BM/hB88HrVtvLwcYZBzae2Xhfihr6IUgkrJPiB4F4NOPsy VCXO7KYejqWQYy0fK+JgmaMlO0PVgssE24C4na5AIy0fclOdfKaJexlslQIr1S378dAzWapJL7STG izM6XypQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mco7B-0018nV-1a; Tue, 19 Oct 2021 12:21:09 +0000 Received: from mail-wm1-x34a.google.com ([2a00:1450:4864:20::34a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mcnzx-0015PG-NF for linux-arm-kernel@lists.infradead.org; Tue, 19 Oct 2021 12:13:44 +0000 Received: by mail-wm1-x34a.google.com with SMTP id k20-20020a7bc414000000b0030dcd454771so1066072wmi.8 for ; Tue, 19 Oct 2021 05:13:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=DHnuaOy9p1LD/61fjq4CO1t0/yktzi5R0H6G7O3QKgQ=; b=lk3KhNsTMuoV5fphW2OJrEAgxIGGD12sA+tP3VzSZuG0/N9jed9FhMYky4JoMvaFrN +x4sMMoqdzzFC43SWfYVVOpAsfikOD+9NnhKBjeye7tX/ZodpmTn/c4ee+4kxccZ51VU 7va8DyRJN6maWNmNRzWTTREvIK23n/rM0URBAPnlrK0XimQkCduqHwnwewzNrwCLTc8U /d2MFLhpRxS6H2KjHdkW96tYBgsNJCHtXcPSgDaHpasRIVddeFfv7qhNkneW+IYJwO5v 9dWgaGj9LZiK33eYs49Nu3b/ZtrJaznu+sfhEVhtXyx/3MGq2Zqpt9Bl76zcGctcJ6gT ycaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=DHnuaOy9p1LD/61fjq4CO1t0/yktzi5R0H6G7O3QKgQ=; b=Utz/mvwnZLlKKhBrVNOVNq26SZJc5chMv68g7oRUoXkLZZmK94iTYtxha2uOXmU4/2 ac5aFuVXS0CLlVhvA5N6je0hWLvvxEZyJGYZYQm++Mde4teEBmobo90AdU3Ki9Esfu+4 uyqq01aUnsq/4dTtkbSAHLCHZozxlzMM1b+18m40DfV7a56yLcKSNG6Oi3VGsJsECQbO QCEBgBvO/WbPCIMNZVbCv5ywFOSt1nOj4KoJ9kBQ+3qEkiwLdD+Yf/UagmBYY680GC+Q sDSmZlL64OE1NX3ZUXfWgyBvFHy/7KpVAAHA2SJZYZd5cVsSBQQUe3sWc7O4nWZGShUE 58EQ== X-Gm-Message-State: AOAM531dcENWtw89xKRSFLBGHZYStfeKFgE4EMqr1Orv7NqkQUi98pZq kY8yD3GnOWDYno4Aflm7S8iWiL4+dqDu X-Google-Smtp-Source: ABdhPJziYoIjlxnulRRJqnFfUHmz1k8SNbs7d5KuqNS+gY2QUofneE5ubXRJhX+TuE7cLXglafWHIUoL6D1m X-Received: from luke.lon.corp.google.com ([2a00:79e0:d:210:59ca:401f:83a8:de6d]) (user=qperret job=sendgmr) by 2002:a05:600c:17ca:: with SMTP id y10mr5762129wmo.62.1634645619541; Tue, 19 Oct 2021 05:13:39 -0700 (PDT) Date: Tue, 19 Oct 2021 13:13:03 +0100 In-Reply-To: <20211019121304.2732332-1-qperret@google.com> Message-Id: <20211019121304.2732332-15-qperret@google.com> Mime-Version: 1.0 References: <20211019121304.2732332-1-qperret@google.com> X-Mailer: git-send-email 2.33.0.1079.g6e70778dc9-goog Subject: [PATCH v2 14/15] KVM: arm64: Expose unshare hypercall to the host From: Quentin Perret To: Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , Catalin Marinas , Will Deacon , Fuad Tabba , David Brazdil , Andrew Walbran Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kernel-team@android.com, qperret@google.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211019_051341_828582_04D1E2CF X-CRM114-Status: GOOD ( 13.53 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Will Deacon Introduce an unshare hypercall which can be used to unmap memory from the hypervisor stage-1 in nVHE protected mode. This will be useful to update the EL2 ownership state of pages during guest teardown, and avoids keeping dangling mappings to unreferenced portions of memory. Signed-off-by: Will Deacon Signed-off-by: Quentin Perret --- arch/arm64/include/asm/kvm_asm.h | 1 + arch/arm64/kvm/hyp/include/nvhe/mem_protect.h | 1 + arch/arm64/kvm/hyp/nvhe/hyp-main.c | 8 +++++ arch/arm64/kvm/hyp/nvhe/mem_protect.c | 33 +++++++++++++++++++ 4 files changed, 43 insertions(+) diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h index 0167f3702c61..59c55aedb0ae 100644 --- a/arch/arm64/include/asm/kvm_asm.h +++ b/arch/arm64/include/asm/kvm_asm.h @@ -63,6 +63,7 @@ enum __kvm_host_smccc_func { /* Hypercalls available after pKVM finalisation */ __KVM_HOST_SMCCC_FUNC___pkvm_host_share_hyp, + __KVM_HOST_SMCCC_FUNC___pkvm_host_unshare_hyp, __KVM_HOST_SMCCC_FUNC___kvm_adjust_pc, __KVM_HOST_SMCCC_FUNC___kvm_vcpu_run, __KVM_HOST_SMCCC_FUNC___kvm_flush_vm_context, diff --git a/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h b/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h index 56445586c755..80e99836eac7 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h +++ b/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h @@ -55,6 +55,7 @@ extern const u8 pkvm_hyp_id; int __pkvm_prot_finalize(void); int __pkvm_host_share_hyp(u64 pfn); +int __pkvm_host_unshare_hyp(u64 pfn); bool addr_is_memory(phys_addr_t phys); int host_stage2_idmap_locked(phys_addr_t addr, u64 size, enum kvm_pgtable_prot prot); diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c index b096bf009144..5e2197db0d32 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c @@ -147,6 +147,13 @@ static void handle___pkvm_host_share_hyp(struct kvm_cpu_context *host_ctxt) cpu_reg(host_ctxt, 1) = __pkvm_host_share_hyp(pfn); } +static void handle___pkvm_host_unshare_hyp(struct kvm_cpu_context *host_ctxt) +{ + DECLARE_REG(u64, pfn, host_ctxt, 1); + + cpu_reg(host_ctxt, 1) = __pkvm_host_unshare_hyp(pfn); +} + static void handle___pkvm_create_private_mapping(struct kvm_cpu_context *host_ctxt) { DECLARE_REG(phys_addr_t, phys, host_ctxt, 1); @@ -184,6 +191,7 @@ static const hcall_t host_hcall[] = { HANDLE_FUNC(__pkvm_prot_finalize), HANDLE_FUNC(__pkvm_host_share_hyp), + HANDLE_FUNC(__pkvm_host_unshare_hyp), HANDLE_FUNC(__kvm_adjust_pc), HANDLE_FUNC(__kvm_vcpu_run), HANDLE_FUNC(__kvm_flush_vm_context), diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c index 205616c9f107..fc542585a964 100644 --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c @@ -757,3 +757,36 @@ int __pkvm_host_share_hyp(u64 pfn) return ret; } + +int __pkvm_host_unshare_hyp(u64 pfn) +{ + int ret; + u64 host_addr = hyp_pfn_to_phys(pfn); + u64 hyp_addr = (u64)__hyp_va(host_addr); + struct pkvm_mem_share share = { + .tx = { + .nr_pages = 1, + .initiator = { + .id = PKVM_ID_HOST, + .addr = host_addr, + .host = { + .completer_addr = hyp_addr, + }, + }, + .completer = { + .id = PKVM_ID_HYP, + }, + }, + .prot = PAGE_HYP, + }; + + host_lock_component(); + hyp_lock_component(); + + ret = do_unshare(&share); + + hyp_unlock_component(); + host_unlock_component(); + + return ret; +}