From patchwork Mon Aug 9 15:24:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 12426833 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 D99B8C4338F for ; Mon, 9 Aug 2021 15:42:00 +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 7A6656101D for ; Mon, 9 Aug 2021 15:42:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7A6656101D 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=VYnKtRsEMVxIFldd6bXc9HyPztC2X39gH4WSFYSOtsM=; b=pcLBBjq7ulAouAsdWfn7/kp9yy flcaGKtFa+i2Xuadd5UzLjn/MT7Y1dOGrxk0OS03dU1ayWYUhytgHACeXhEcnaYFsDnk93vmtVoj0 2c9N37r9BbGv4v9d5lHNZkcW0lIOkifgH8Dy4606XxHNqNGnwUhZAkTa0DkxgobyhPby3d/MZ1Kel EeORFb//v/r170tIES429Vccf1BywOuc96KGNXNUJdI4hHlXEodwHzn1LpaxrAZIbU5uZ2FWwJBUh dTuh0vBmm+YZ4Ce/CbCLC3tDksNzAefI+uibpkyL091Nv2ZE1oTTRmPDOOEuo83PaQZR24YXEBv+o WogrmIaw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mD7N3-001Dbi-0H; Mon, 09 Aug 2021 15:39:21 +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 1mD79j-00184l-8Y for linux-arm-kernel@lists.infradead.org; Mon, 09 Aug 2021 15:25:38 +0000 Received: by mail-wm1-x34a.google.com with SMTP id l38-20020a05600c1d26b0290259bef426efso113681wms.8 for ; Mon, 09 Aug 2021 08:25:34 -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=0vnFX0HCkFp8ZLTU0btBJYZAdzWXKCWbI3FuYOfCODA=; b=edLLNeSUJUuSeZh6U5LgHuiFbQdxbqRKi/NQ1RSRnsUEn2S/8ryLev1RWgMSfDbltm Om9IrwxtxrsFpwCskBaMEJ7xBMB6hChrlzhzMzZ2whQvKh0X0/PsQAyhN2UbcMabEKhJ kFITxof5dzgHb27rpT/TUwsw9eujgADfYDSuydpjHXLWRa3f3mUrl1r2tJHF5HcYrnXM ZVct81ad5/jrKV4yq33XFH/l0LAM02qWUJwCBxnaoSuNVHOUDowrr9GS0w/R/KbWvIzV XsiLCk2wB36vg/uxYgid0GyY+bEKFJ/s794tI7nnae4HsUsaHCOpJbS240pLizQYB85F EWrA== 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=0vnFX0HCkFp8ZLTU0btBJYZAdzWXKCWbI3FuYOfCODA=; b=uDBt5nppB9UfxLWTJDmdvv53BIuxLfK59WK5li3wHJpnWgBnSLFt+kh6C6D3GjfQbS EizTL36Y6Yz3JesKPf5gOgqFhS9CS2R3UyQD7eZYocCB88pZDE2aztnUnM+2MhZQ3YSu LKQ+IYPRC6unKx3dLCR0vNcGDOxnAKLIjKsLvt8h7Hr7utAxQWwWYwenIuuXJNm+bWis /A0idQp/gOoZimqpBQJKJ+97tIK+lHbqNWeCSPNEnLaiTMtvWwgZAIwPzIwyH54KaZKE w46FrNZVxsQW06EejVGOMoFEEOJLSqWYDvunKJmzuk/DkMW1V9tbHzXHr8UL4575vaE1 fLmA== X-Gm-Message-State: AOAM531sE50C6GmSvC6zIOjWuPTEpX0NDvm9kL3cchkVU6ep0VSOqWBE REYMrZndWBxWXOqKfHXMsKIhorEcbfhm X-Google-Smtp-Source: ABdhPJyIOtnzxP4S0R25oU2iubMhTBhg+aNqUgDs+Hxip8y4Nj2Lxx59WuSTFwfisX1gdgavPWTXBcPgInrK X-Received: from luke.lon.corp.google.com ([2a00:79e0:d:210:b0e8:d460:758b:a0ae]) (user=qperret job=sendgmr) by 2002:a7b:cb99:: with SMTP id m25mr33616400wmi.90.1628522733253; Mon, 09 Aug 2021 08:25:33 -0700 (PDT) Date: Mon, 9 Aug 2021 16:24:46 +0100 In-Reply-To: <20210809152448.1810400-1-qperret@google.com> Message-Id: <20210809152448.1810400-20-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 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, qperret@google.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210809_082535_402050_C9F199B5 X-CRM114-Status: GOOD ( 13.90 ) 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 Reviewed-by: Fuad Tabba --- 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;