From patchwork Mon Aug 9 15:24:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 12426821 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=-17.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 CC624C4338F for ; Mon, 9 Aug 2021 15:33:57 +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 78D8C6101D for ; Mon, 9 Aug 2021 15:33:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 78D8C6101D 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=zCE9/3a5vHuargD2L4pcNio5BL4cdqED9IOCjNj3DmY=; b=Qp7GWt/ZyP9SdggL5Z2x4pZ09k Q/Kh+HIr/N9qqwwq7V90sY688860UCao+brFkg736Bmzgv0F7YbKMTIUwoA/r7NnZ0QYmlWJDnUsw nPHG9nqhTBANzBooim5HSpV1P7BAMOpmcY4Qczl5bH29/1nU5S8B2gyWFEWeKirpIqotcsw5wOei3 38w7b2/uiT9Juhw214AEV794CKJeEXvHNBydLxD/yHmnvdp5x8zqRP6+3W2nmk30od6snLBB7mHh7 nNLELNaNVi0S8KQsqt75eaB+IxJ4DtyORVm0lWPTY74TTVUpNnEP3z8vGGufQXtfwXQMnTgDcJzV0 EJyHLm0A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mD7FN-001AlA-E4; Mon, 09 Aug 2021 15:31:26 +0000 Received: from mail-qt1-x849.google.com ([2607:f8b0:4864:20::849]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mD79V-0017xs-Uz for linux-arm-kernel@lists.infradead.org; Mon, 09 Aug 2021 15:25:23 +0000 Received: by mail-qt1-x849.google.com with SMTP id x15-20020ac87a8f0000b0290294d1eeaa1dso706770qtr.13 for ; Mon, 09 Aug 2021 08:25:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=3dBIi1YzqMEm+UlYWRCSS5kKhcRIzlI2kVO6oR1gAJY=; b=pwqfES+b/309iPvlv8E1ftMhSnhlZy8mcMABvDRuAotG2budtPOdgJb73oPI6/MSGD ILhOvPTq8aIdf06m1VIM0yJOfipj9IDRQygTQK0MXZQ78+f+s6FJNc4eruv9GBpHUATi 3DPVRIxc+WjDdgR385vu2hDXy4mP0G3jEB7NeE0p5xd7Tsw9AwVodm/pABL8JAkqLUJm Dedj5LkITe1ybQH+GMWWBsZx05lk6S7Iqa2v9OVbbFvui/pxn7ZMcFeqJTXh1zGzeV7/ wCMz42JxwEpefj4CSksac16Vm16+9iQ0mxJgbtQYa+MRG8v10SN4Entl6tuQ2OhQ2q3X lIXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=3dBIi1YzqMEm+UlYWRCSS5kKhcRIzlI2kVO6oR1gAJY=; b=dkzJuPecRjvQGQuT5mM2uCO2TIAwjDEzOqqqVIpla+EuL7xUPrj1gyRmBiLcis71sh n19QzyuaiKGzsO5tHgTtA0OdNfYRgCL7+Wh9mZLTlbxwDk6rejeCBvVZFCPWuUfocN91 4XoE6q1RVaVI9aCwn/vSU06M/p+EvcvbJ4UtqniFcvTEPJ6/tix51BtMrSD4u1m5/IV4 Xb3Y0j7wd8mHL1Q5w347DxBbOWe2W7tK0kaJh0R8Vaxq5wgNBBRerfWNLF+/8MLafjmS wsLaeOi74BLU2Vok/bR9EfdzdNX78YbS4l3W7X8MMNZpy7Qpioffu3FwNbhezU59/5U5 j7sw== X-Gm-Message-State: AOAM5336YdQJNcrMOkoxopQevLt/cbFnpCqSyptyKkW1qERUIJ/9L9d/ fM/coGP8I7cm9tqffTDVe5obBPZnTtbF X-Google-Smtp-Source: ABdhPJwTAF1XYWSKb67BxPuZMFA3SIWFIr0NEvX9FTJFVSSti+daWMWMqdeklw8++yGxusAYBtawMwClTWQ8 X-Received: from luke.lon.corp.google.com ([2a00:79e0:d:210:b0e8:d460:758b:a0ae]) (user=qperret job=sendgmr) by 2002:a05:6214:d4b:: with SMTP id 11mr12803043qvr.44.1628522719790; Mon, 09 Aug 2021 08:25:19 -0700 (PDT) Date: Mon, 9 Aug 2021 16:24:40 +0100 In-Reply-To: <20210809152448.1810400-1-qperret@google.com> Message-Id: <20210809152448.1810400-14-qperret@google.com> Mime-Version: 1.0 References: <20210809152448.1810400-1-qperret@google.com> X-Mailer: git-send-email 2.32.0.605.g8dce9f2422-goog Subject: [PATCH v4 13/21] KVM: arm64: Expose host stage-2 manipulation helpers From: Quentin Perret To: maz@kernel.org, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, will@kernel.org Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, ardb@kernel.org, qwandor@google.com, tabba@google.com, dbrazdil@google.com, kernel-team@android.com, qperret@google.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210809_082522_065707_81A2888B X-CRM114-Status: GOOD ( 12.51 ) 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 We will need to manipulate the host stage-2 page-table from outside mem_protect.c soon. Introduce two functions allowing this, and make them usable to users of mem_protect.h. Signed-off-by: Quentin Perret Reviewed-by: Fuad Tabba --- arch/arm64/kvm/hyp/include/nvhe/mem_protect.h | 2 ++ arch/arm64/kvm/hyp/nvhe/mem_protect.c | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h b/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h index 87b1690c439f..0849ee8fa260 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h +++ b/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h @@ -49,6 +49,8 @@ extern struct host_kvm host_kvm; int __pkvm_prot_finalize(void); int __pkvm_mark_hyp(phys_addr_t start, phys_addr_t end); +int host_stage2_idmap_locked(phys_addr_t addr, u64 size, enum kvm_pgtable_prot prot); +int host_stage2_set_owner_locked(phys_addr_t addr, u64 size, u8 owner_id); int kvm_host_prepare_stage2(void *pgt_pool_base); void handle_host_mem_abort(struct kvm_cpu_context *host_ctxt); diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c index 6fed6772c673..f95a5a4aa09c 100644 --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c @@ -273,6 +273,22 @@ static int host_stage2_adjust_range(u64 addr, struct kvm_mem_range *range) return 0; } +int host_stage2_idmap_locked(phys_addr_t addr, u64 size, + enum kvm_pgtable_prot prot) +{ + hyp_assert_lock_held(&host_kvm.lock); + + return host_stage2_try(__host_stage2_idmap, addr, addr + size, prot); +} + +int host_stage2_set_owner_locked(phys_addr_t addr, u64 size, u8 owner_id) +{ + hyp_assert_lock_held(&host_kvm.lock); + + return host_stage2_try(kvm_pgtable_stage2_set_owner, &host_kvm.pgt, + addr, size, &host_s2_pool, owner_id); +} + static bool host_stage2_force_pte_cb(u64 addr, u64 end, enum kvm_pgtable_prot prot) { /* @@ -309,7 +325,7 @@ static int host_stage2_idmap(u64 addr) if (ret) goto unlock; - ret = host_stage2_try(__host_stage2_idmap, range.start, range.end, prot); + ret = host_stage2_idmap_locked(range.start, range.end - range.start, prot); unlock: hyp_spin_unlock(&host_kvm.lock);