From patchwork Wed Feb 1 12:53:25 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: 13124401 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 B4666C636CD for ; Wed, 1 Feb 2023 14:19:27 +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=NCylvE5aY9183mjocd7f3Mi1KVnGcdHSGmjl0imz5dU=; b=Hlux4MkDHAFh+z DxzY/icW3c76a4J9jzgaMQ8doGKG97Qv/KvHzBnMCeKuzZF4gjtVqVASwB7aW0IxsyJXflNTCY2SF LBGwLmvjptQAiiaT3+nJoFzLR498bsNcZE9+/rj3uy64iGr15eVNyVHUECT3mNpZOpMQoNkYme9kQ XVZjq3OgmgX/hYHcxQRNu2wzycrKMPpyUKp5codukZ6yI117cIh2kayVXUHWV4iIzD9crjH/YHaeA glLC/Y+myRMSDgzRmfpb8t+i8T0LjBQ0sWPC2OZsc3BfEp2lJQRUElb8XW2csiVQZ2rZjRBOxNTus EF+Jg9UbkdZKNIymiymQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNDwM-00CHsr-Ua; Wed, 01 Feb 2023 14:18:24 +0000 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNCiO-00BnGh-Bn for linux-arm-kernel@lists.infradead.org; Wed, 01 Feb 2023 12:59:53 +0000 Received: by mail-wr1-x429.google.com with SMTP id m14so16761114wrg.13 for ; Wed, 01 Feb 2023 04:59:52 -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=3XQ8jSpys2Hws9/7ixJG0IKBklTR26Fi7D4CXfNjCZM=; b=GWi08w8bd79vvKrXk4BmiTVSIiEylmmpgFWd2pmPUbgeLTqOFj0BxthGC7YaErnCgM +3wzH8OdCcZne3jjsM3iX6FsHh2Qw19742RfrWV0OYuOAdgikEKePVcpTnrnNNpv/OFZ Qt8b8r18XGgsfkaJBSyC7bENzqhfBnWrK4JVC1xFCtwNme4oMvRC7uUW2QKOCgcEY76Z 0gj8tAD4dK4bj/e/ok5esM2nOlSukbC74w2yWTnJYK0GaPyR7G03JlruX/JPDpt9wXFA xB8eodzYviO5c6lRMG/LMY/TCARvCBwZnKsSutQ33xe3LQZYEABHMW6UqQOzFKEQJAZD GGZA== 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=3XQ8jSpys2Hws9/7ixJG0IKBklTR26Fi7D4CXfNjCZM=; b=MGLfEPBorpKg+HJowtD54OvIs/fEIW84VD4yHagPSVwtySBiRrbZ6/F1DUXarLzaTT mw8EzIa5dHuMnrVzM6cjTjlCwc1EtuNsp+fdOHounWWKreWuH/EfnBiAEA9vQL7iONIM PtVHx0FQSsq3h7ICEmqviXiGMx/Evzl9jfu6ouIKP+vf/yMY1WOoyj3c1AniGPEEStZ6 yuHlssA3tGxNI/pBkRhXn6DzqYb8wFyykW6POEmToi5/KwafQ/P/LG2vjgU3q+lND7cZ eAvdB4lyGfTXEeIg4qSWAgi8Lwisirr9oE7dSVJ6K91QZKDM+MEQuVEHvYXDAfKow1vx WZLA== X-Gm-Message-State: AO0yUKVDP75436bVLb8YboUX3COL5vrWLNkulG3f587LeIJEUWTJ2ef1 vCuE1mKiQgy/dIk41RzFv5fONQ== X-Google-Smtp-Source: AK7set+p3RZCyUqjM7HvNLHrPv8GDGafCYhqQ48BWrrnF24tXgDMI5DbpRPrwpMXGq/D5XyaJddJZw== X-Received: by 2002:a5d:4c49:0:b0:2bd:ed75:808c with SMTP id n9-20020a5d4c49000000b002bded75808cmr5620860wrt.38.1675256391893; Wed, 01 Feb 2023 04:59:51 -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.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 04:59:51 -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 41/45] KVM: arm64: pkvm: Add __pkvm_host_add_remove_page() Date: Wed, 1 Feb 2023 12:53:25 +0000 Message-Id: <20230201125328.2186498-42-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_045952_418711_7D4718FB X-CRM114-Status: GOOD ( 12.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 Add a small helper to remove and add back a page from the host stage-2. This will be used to temporarily unmap a piece of shared sram (device memory) from the host while we handle a SCMI request, preventing the host from modifying the request after it is verified. Signed-off-by: Jean-Philippe Brucker --- arch/arm64/kvm/hyp/include/nvhe/mem_protect.h | 1 + arch/arm64/kvm/hyp/nvhe/mem_protect.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h b/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h index a363d58a998b..a7b28307604d 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h +++ b/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h @@ -75,6 +75,7 @@ int __pkvm_guest_share_host(struct pkvm_hyp_vcpu *hyp_vcpu, u64 ipa); int __pkvm_guest_unshare_host(struct pkvm_hyp_vcpu *hyp_vcpu, u64 ipa); int __pkvm_host_share_dma(u64 phys_addr, size_t size, bool is_ram); int __pkvm_host_unshare_dma(u64 phys_addr, size_t size); +int __pkvm_host_add_remove_page(u64 pfn, bool remove); 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/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c index dcf08ce03790..6c3eeea4d4f5 100644 --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c @@ -1954,3 +1954,20 @@ int __pkvm_host_reclaim_page(u64 pfn) return ret; } + +/* + * Temporarily unmap a page from the host stage-2, if @remove is true, or put it + * back. After restoring the ownership to host, the page will be lazy-mapped. + */ +int __pkvm_host_add_remove_page(u64 pfn, bool remove) +{ + int ret; + u64 host_addr = hyp_pfn_to_phys(pfn); + u8 owner = remove ? PKVM_ID_HYP : PKVM_ID_HOST; + + host_lock_component(); + ret = host_stage2_set_owner_locked(host_addr, PAGE_SIZE, owner); + host_unlock_component(); + + return ret; +}