From patchwork Wed Feb 1 12:52:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 13124371 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 6A22FC636CD for ; Wed, 1 Feb 2023 14:03:58 +0000 (UTC) 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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=bhTy/4kK7EKI79EjmQt2B3l6iGyYpoGHg5+1mnGrxBI=; b=QMLySj9+z2Lsli INSUzAmsxd4mXmdeLvkwbFcj1CcHEsLVxBkNMdEto88oHDcPgzR7HEULzEnGkluaaikBB7yWbGKqB m6xgPKS9e43CDKZtGlRjkTKa9CpJ4Rt/u47rPXxMGv2yp8IVLm/XMGBt76V+RYTgwyU0RZYWz+wOi rUBZOtCqSBqPdybO+YrUK0MLLS8Izc2Zcux7JnWwb2aDgFbw98Jc82WlRBduGy3AbgGRGcXGMIipC 5pRdR8c6ncqjvuz1yXX/55Mayi0AijXFZwMRSgp0BCHzAaQc+jOCpZSTeJRBPCpDmHQ3E5ioDxJKK V9Rg2x6z+ww6Ws1Bi4uA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNDhY-00CBjT-MW; Wed, 01 Feb 2023 14:03:04 +0000 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNCi2-00BnIA-ED for linux-arm-kernel@lists.infradead.org; Wed, 01 Feb 2023 12:59:35 +0000 Received: by mail-wm1-x332.google.com with SMTP id l8so12605666wms.3 for ; Wed, 01 Feb 2023 04:59:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RLOTGdIX5XzH+Jwl3kF9DSu2jc0/WXz1kG1OARrYJNM=; b=Q3d2qtJCq3BIVZGKfu+1IbjBWHzFBo5/Xb5HFUtbvMJiuz3cAPjEqCHt3UwOffYZxE TMFUSJOltSsIXD8YBlXzzMeEB3fEpiE9zUaiuEEPBVru2iH+3SS3201GANWWtgrCmLfp yp/r96OfA0uSfjIy1uIBj8EViI4HE3mP0t4qaiaKs8CSwJRo9psQTTID6YbKjjmjvw5I ecCHZjebTzN1f6avWcf8CrPIb6hGrng7Q4dsF98hbcyuENPsy9HlSYBL62deV6Pt96s+ aDVggipAu4GpMD4mgFQZmn9cMcZnEDM6Akk5nC8sqLdcDYZCpkG4NS3wVlZ2x/Lpsq6r WDGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RLOTGdIX5XzH+Jwl3kF9DSu2jc0/WXz1kG1OARrYJNM=; b=AeGEM6xKV4LTkLsFB1LnHJ2gihf8YTegPz5MqTNdVRzhmBhWAIasCAE1RwkEMIAuMz hybuKaD8VkZB/jMH2z3nNZ1utm0oJ80AVj0EKK753ilJcs0QPDQ7Kfx0j2+PxVQcwztl YUAVAwHEEDgguONXF1t/s7qMm1Cv0/gHfZkZfLR8lj2A1w71TTA4Yuabk2CKUTu5XT1z wq1Z1t1B65RljKsk9m3uQ74+dGSczmIcmiKPOpdkR7HxCsYXA+zQhm8WP2VqycQOZAXt 6xIGZmgdOBDcwO2TYeAkwLh5hbfyjnB/9IHqeulPORNjFWYcCqGp0kywNcSbBvXnxTvC wXyA== X-Gm-Message-State: AO0yUKWOxu0YCVG5KDo+WFs35odKcgJZ8NZ++G8GJrGh3r/m2S/1s784 FjxpfPIATC4eHzvdI/MXrcmf4w== X-Google-Smtp-Source: AK7set/rYkvZAy6++0J4vjVN94POb8/wXVqA/8/v2lPmHrVQwzFxOEu9D5CiFkQiJcSsOv/7hSdgVQ== X-Received: by 2002:a05:600c:1989:b0:3db:2d7e:1204 with SMTP id t9-20020a05600c198900b003db2d7e1204mr2027422wmq.27.1675256366507; Wed, 01 Feb 2023 04:59:26 -0800 (PST) Received: from localhost.localdomain (054592b0.skybroadband.com. [5.69.146.176]) by smtp.gmail.com with ESMTPSA id m15-20020a056000024f00b002bfae16ee2fsm17972811wrz.111.2023.02.01.04.59.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 04:59:26 -0800 (PST) From: Jean-Philippe Brucker To: maz@kernel.org, catalin.marinas@arm.com, will@kernel.org, joro@8bytes.org Cc: robin.murphy@arm.com, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com, smostafa@google.com, dbrazdil@google.com, ryan.roberts@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, iommu@lists.linux.dev, Jean-Philippe Brucker Subject: [RFC PATCH 09/45] KVM: arm64: pkvm: Add pkvm_create_hyp_device_mapping() Date: Wed, 1 Feb 2023 12:52:53 +0000 Message-Id: <20230201125328.2186498-10-jean-philippe@linaro.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230201125328.2186498-1-jean-philippe@linaro.org> References: <20230201125328.2186498-1-jean-philippe@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230201_045930_507348_D3BFAB99 X-CRM114-Status: GOOD ( 13.21 ) 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 Add a function to map a MMIO region in the hypervisor and remove it from the host. Hypervisor device drivers use this to reserve their regions during setup. Signed-off-by: Jean-Philippe Brucker --- arch/arm64/kvm/hyp/include/nvhe/mm.h | 1 + arch/arm64/kvm/hyp/nvhe/setup.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/arch/arm64/kvm/hyp/include/nvhe/mm.h b/arch/arm64/kvm/hyp/include/nvhe/mm.h index d5ec972b5c1e..84db840f2057 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/mm.h +++ b/arch/arm64/kvm/hyp/include/nvhe/mm.h @@ -27,5 +27,6 @@ int __pkvm_create_private_mapping(phys_addr_t phys, size_t size, enum kvm_pgtable_prot prot, unsigned long *haddr); int pkvm_alloc_private_va_range(size_t size, unsigned long *haddr); +int pkvm_create_hyp_device_mapping(u64 base, u64 size, void __iomem *haddr); #endif /* __KVM_HYP_MM_H */ diff --git a/arch/arm64/kvm/hyp/nvhe/setup.c b/arch/arm64/kvm/hyp/nvhe/setup.c index 629e74c46b35..de7d60c3c20b 100644 --- a/arch/arm64/kvm/hyp/nvhe/setup.c +++ b/arch/arm64/kvm/hyp/nvhe/setup.c @@ -259,6 +259,23 @@ static int fix_host_ownership(void) return 0; } +/* Map the MMIO region into the hypervisor and remove it from host */ +int pkvm_create_hyp_device_mapping(u64 base, u64 size, void __iomem *haddr) +{ + int ret; + + ret = __pkvm_create_private_mapping(base, size, PAGE_HYP_DEVICE, haddr); + if (ret) + return ret; + + /* lock not needed during setup */ + ret = host_stage2_set_owner_locked(base, size, PKVM_ID_HYP); + if (ret) + return ret; + + return ret; +} + static int fix_hyp_pgtable_refcnt(void) { struct kvm_pgtable_walker walker = {