From patchwork Thu Jul 29 13:28:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 12408775 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 BCAE6C4338F for ; Thu, 29 Jul 2021 13:46:29 +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 83F5760EB5 for ; Thu, 29 Jul 2021 13:46:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 83F5760EB5 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=8aco4kGTWzD5MwgAKZxpS/mQGkm+eSj67kl71t+7DSY=; b=KII4dLyRPdc6tz9BMPlBzUWCIv WymdrTg0sVj7U9SOuDr8hdSq4rygk7gdEMONRsQyPcuosVXswNlX36NAR3vH+5fHh1gNxqH7s8Oof NYHxB8m4yvycBkWWf/JIXgiuF8xmwEr+/C2RA1ZnLoWOOVcJEWhc1CjPmWcWGaT9x3GOZIXVmpqFU Vd6G4153VT6bdr+oWyBhqYRQ0Jc0ehHobRMG2nORdWgvW8ISxix3eVQVSPxQ1vmXUgtPsUPpP5//F mjGSHbaqZ+gtzHivKmlcf1k7wc6uqDSlIHNE4idMmCArsN/rZZKfmQQk6DPlwk+3rhJq0Kj2adPK7 WOWGJg5w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m96KW-004KPV-RJ; Thu, 29 Jul 2021 13:44:09 +0000 Received: from mail-qt1-x84a.google.com ([2607:f8b0:4864:20::84a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m965z-004Emj-Ox for linux-arm-kernel@lists.infradead.org; Thu, 29 Jul 2021 13:29:09 +0000 Received: by mail-qt1-x84a.google.com with SMTP id t35-20020a05622a1823b02902647b518455so2758734qtc.3 for ; Thu, 29 Jul 2021 06:29:06 -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=PD2lJrK2uUAJidILwsX5pR8ZyvNUyZDv1OnaXJdJLhM=; b=mUuZZtK9nPtQzaSeRR1efvqBrUoJ0pqBZlk3FM19wBDIbLOvb8fBAK1zLHnHmRvgG4 9+m8SNZemfJ5wjNL0ad4SiPyjYjEBlLoS8Tyn4uwj2sswKXw+5b34Cpk+2cNl0zxU9i2 hb1UtR4PqkuvDCfrkQgC0MmfZumGrmMdvx63kJ33dQX7N17wUy5Vt6SMNZbQpHP5yLox bd8gesl5DHYmN7n9sV5lvWk1BJ0SWoWsa969E0R98/3453gA3Yw8Lno5XA7wFKvbI4kS Ku3g9VDc96QVgpM4vZGdkPZ0QH5KCfDWuAHB2CAaVZfb6Aalj1LyRfmpbi6Z8uylubmZ KXnA== 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=PD2lJrK2uUAJidILwsX5pR8ZyvNUyZDv1OnaXJdJLhM=; b=nhMRDQG+oK01WCl5Y/tmqz6ewiiaKtBCqBLQUdW7j8gHrn+f0TGHQbl8+7YxE1ITOe 8LsGb4EDSHp7hyKOJDDiQsL4Vu+lztcL2l51zl5stLwuUTiWB4TUC1ipJNIEcJxJ1eah QGhetutKRfD8hvq1QUeioXD45avlABrGpJYxPKxuVQtZVEW4NF+sYZgXwTqnztVS99L7 6lb9t9WDApXJURJgZ3aydKGS7l3EfGq0KLkA0VXj7nG+Qjp4Oq53pyN3wjCEa9HPGLpt uYJ7TGwVKOcmwOhNUcRRXnmnhsW+4rA1PcFaW6dVce/UQwMs6Vp5eAOZWzFkdIMpVgGG yWRw== X-Gm-Message-State: AOAM530/13p9ymcJde5RalCK8Z3/+LmL+jhGh55vdGCB0orxC1ZUVVrp 2rgMtRMSeej4Tc5SiCtDynfbw0XLE+fb X-Google-Smtp-Source: ABdhPJz10hpfq0SGJNMP70xRlPb0dobUvsFM7yqmK2aN+qLJctMkUjDYhRjEE2aZ3LvI5a9WzZnTi+0sHxt+ X-Received: from luke.lon.corp.google.com ([2a00:79e0:d:210:293a:bc89:7514:5218]) (user=qperret job=sendgmr) by 2002:a05:6214:10e6:: with SMTP id q6mr4966976qvt.11.1627565346131; Thu, 29 Jul 2021 06:29:06 -0700 (PDT) Date: Thu, 29 Jul 2021 14:28:16 +0100 In-Reply-To: <20210729132818.4091769-1-qperret@google.com> Message-Id: <20210729132818.4091769-20-qperret@google.com> Mime-Version: 1.0 References: <20210729132818.4091769-1-qperret@google.com> X-Mailer: git-send-email 2.32.0.432.gabb21c7263-goog Subject: [PATCH v3 19/21] KVM: arm64: Refactor protected nVHE stage-1 locking 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, Quentin Perret X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210729_062907_886136_FBD6A881 X-CRM114-Status: GOOD ( 13.25 ) 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 Refactor the hypervisor stage-1 locking in nVHE protected mode to expose a new pkvm_create_mappings_locked() function. This will be used in later patches to allow walking and changing the hypervisor stage-1 without releasing the lock. Signed-off-by: Quentin Perret --- arch/arm64/kvm/hyp/include/nvhe/mm.h | 1 + arch/arm64/kvm/hyp/nvhe/mm.c | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/hyp/include/nvhe/mm.h b/arch/arm64/kvm/hyp/include/nvhe/mm.h index 8ec3a5a7744b..c76d7136ed9b 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/mm.h +++ b/arch/arm64/kvm/hyp/include/nvhe/mm.h @@ -23,6 +23,7 @@ int hyp_map_vectors(void); int hyp_back_vmemmap(phys_addr_t phys, unsigned long size, phys_addr_t back); int pkvm_cpu_set_vector(enum arm64_hyp_spectre_vector slot); int pkvm_create_mappings(void *from, void *to, enum kvm_pgtable_prot prot); +int pkvm_create_mappings_locked(void *from, void *to, enum kvm_pgtable_prot prot); int __pkvm_create_mappings(unsigned long start, unsigned long size, unsigned long phys, enum kvm_pgtable_prot prot); unsigned long __pkvm_create_private_mapping(phys_addr_t phys, size_t size, diff --git a/arch/arm64/kvm/hyp/nvhe/mm.c b/arch/arm64/kvm/hyp/nvhe/mm.c index a8efdf0f9003..6fbe8e8030f6 100644 --- a/arch/arm64/kvm/hyp/nvhe/mm.c +++ b/arch/arm64/kvm/hyp/nvhe/mm.c @@ -67,13 +67,15 @@ unsigned long __pkvm_create_private_mapping(phys_addr_t phys, size_t size, return addr; } -int pkvm_create_mappings(void *from, void *to, enum kvm_pgtable_prot prot) +int pkvm_create_mappings_locked(void *from, void *to, enum kvm_pgtable_prot prot) { unsigned long start = (unsigned long)from; unsigned long end = (unsigned long)to; unsigned long virt_addr; phys_addr_t phys; + hyp_assert_lock_held(&pkvm_pgd_lock); + start = start & PAGE_MASK; end = PAGE_ALIGN(end); @@ -81,7 +83,8 @@ int pkvm_create_mappings(void *from, void *to, enum kvm_pgtable_prot prot) int err; phys = hyp_virt_to_phys((void *)virt_addr); - err = __pkvm_create_mappings(virt_addr, PAGE_SIZE, phys, prot); + err = kvm_pgtable_hyp_map(&pkvm_pgtable, virt_addr, PAGE_SIZE, + phys, prot); if (err) return err; } @@ -89,6 +92,17 @@ int pkvm_create_mappings(void *from, void *to, enum kvm_pgtable_prot prot) return 0; } +int pkvm_create_mappings(void *from, void *to, enum kvm_pgtable_prot prot) +{ + int ret; + + hyp_spin_lock(&pkvm_pgd_lock); + ret = pkvm_create_mappings_locked(from, to, prot); + hyp_spin_unlock(&pkvm_pgd_lock); + + return ret; +} + int hyp_back_vmemmap(phys_addr_t phys, unsigned long size, phys_addr_t back) { unsigned long start, end;