Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp2073983rwb; Thu, 27 Jul 2023 01:21:14 -0700 (PDT) X-Google-Smtp-Source: APBJJlE18yPj2v20JANZ1HL0bFx5lJuBUOjHbyc4GFqtWnd2a42M2FA9ye+HvE5//GUtjYzHm906 X-Received: by 2002:a05:6808:8ca:b0:3a4:5063:ddaf with SMTP id k10-20020a05680808ca00b003a45063ddafmr2043262oij.55.1690446073937; Thu, 27 Jul 2023 01:21:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690446073; cv=none; d=google.com; s=arc-20160816; b=wGUIDH70Zf7yEIJqpECOgPUnPKzGxpyjEBp85jWE6ihzLdfEkjrDfXZ2203iEfFwrq 5+bVsCsbrsGQfaFkTxagGEEH6td5CmTU/8D8NMCa6HaG4MWVgd9hzCPDKpjc8HiKCLU3 m4+Ojj566o8EunJA+oZ5TndtPJbnZKmPksI6sM2Ef23f3RhOb1Jmo9ATV8u+xzvmMHVH 0TAoPrHZC7Qk3dc9HMPq8b+woraPJGvxK31jLpFFTSTEhyWs3Xmrlwl9pN+zrgkf8q97 c5burt2uJwTIDHtgEfwJL0psbHiz+xAtRHg0NZpOSoc9KpGZb6FoTxpw1fUIJ20ptRB4 7yNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=dlwzZMYRKarw4YgR99j1yMBfKkLE3s947ec5MMti9Wo=; fh=IpnuE+RKpNePEqRSuAArG1+9fEwx7AzCESeKwmiJLnA=; b=SqN86lW90gjKxf1zaGd5q0cN/eY+wbZ9Qipl3me1MndPv43At5dn2ImnnJ5ay7VpP2 /cjzn08fGrkmLfOZ5BAn579SJPuEcZzsdzsP0xAyBVUTG5B+G6J3da2wtb7Ga2ukjs/q I9e9djNBrKE7m7KbqKhev/DTxuPwZOL642IrnljmEcu/NidEf+VsZsuR1xyMroqmFkwd cflOAFQvLkOVx5SukzoFhqeBd8RYk/GNLL7Jx2lWbOcMIGPoE5vj1EBDalxH4p25KSed fEQthk8i1xlhELbgWfxPwiynGEwB3xETFVFdlz3gXomqQy41SnYjpBFeSfzk/QY0b9SE ZPzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=Tro6WKv9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e129-20020a636987000000b0054fdcafcc67si888873pgc.604.2023.07.27.01.21.01; Thu, 27 Jul 2023 01:21:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=Tro6WKv9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233716AbjG0IEh (ORCPT + 99 others); Thu, 27 Jul 2023 04:04:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233741AbjG0ICy (ORCPT ); Thu, 27 Jul 2023 04:02:54 -0400 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 530372D7D; Thu, 27 Jul 2023 01:00:24 -0700 (PDT) X-UUID: 9f2f38702c5311eeb20a276fd37b9834-20230727 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=dlwzZMYRKarw4YgR99j1yMBfKkLE3s947ec5MMti9Wo=; b=Tro6WKv9SPt7yQFeNZ/Oozsxg6l/i/yI2ckIFm6irDNPyIXc4Si9pBAb1AdE9qNarflH/q/fk8ZEC9ErEwAtQlqsTbKA5Hwx1pRK5tg3teGzRxabSf4AC0woL3ZewlaJmnOrPSVYc9+8kmNCLRcLr7Dr3ZCKiDBcZx2BvTZfers=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.29,REQID:06cb67a4-7961-4b08-86be-ab4d625fc1b5,IP:0,U RL:0,TC:0,Content:-25,EDM:0,RT:0,SF:95,FILE:0,BULK:0,RULE:Release_Ham,ACTI ON:release,TS:70 X-CID-INFO: VERSION:1.1.29,REQID:06cb67a4-7961-4b08-86be-ab4d625fc1b5,IP:0,URL :0,TC:0,Content:-25,EDM:0,RT:0,SF:95,FILE:0,BULK:0,RULE:Spam_GS981B3D,ACTI ON:quarantine,TS:70 X-CID-META: VersionHash:e7562a7,CLOUDID:594cd9b3-a467-4aa9-9e04-f584452e3794,B ulkID:230727160017C2IBS54M,BulkQuantity:2,Recheck:0,SF:28|17|19|48|38|29,T C:nil,Content:0,EDM:-3,IP:nil,URL:11|1,File:nil,Bulk:40,QS:nil,BEC:nil,COL :0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_FAS,TF_CID_SPAM_FSD,TF_CID_SPAM_ULN,TF_CID_SPAM_SNR, TF_CID_SPAM_SDM,TF_CID_SPAM_ASC X-UUID: 9f2f38702c5311eeb20a276fd37b9834-20230727 Received: from mtkmbs13n1.mediatek.inc [(172.21.101.193)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1584944357; Thu, 27 Jul 2023 16:00:15 +0800 Received: from mtkmbs11n2.mediatek.inc (172.21.101.187) by mtkmbs13n1.mediatek.inc (172.21.101.193) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Thu, 27 Jul 2023 16:00:14 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs11n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Thu, 27 Jul 2023 16:00:14 +0800 From: Yi-De Wu To: Yingshiuan Pan , Ze-Yu Wang , Yi-De Wu , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Corbet , Catalin Marinas , Will Deacon , Arnd Bergmann , Matthias Brugger , AngeloGioacchino Del Regno CC: , , , , , , David Bradil , Trilok Soni , Ivan Tseng , Jade Shih , My Chuang , Shawn Hsiao , PeiLun Suei , Liju Chen , Willix Yeh Subject: [PATCH v5 08/12] virt: geniezone: Add memory region support Date: Thu, 27 Jul 2023 16:00:01 +0800 Message-ID: <20230727080005.14474-9-yi-de.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20230727080005.14474-1-yi-de.wu@mediatek.com> References: <20230727080005.14474-1-yi-de.wu@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Jerry Wang" Hypervisor might need to know the precise purpose of each memory region, so that it can provide specific memory protection. We add a new uapi to pass address and size of a memory region and its purpose. Signed-off-by: Jerry Wang Signed-off-by: Liju-clr Chen Signed-off-by: Yi-De Wu --- arch/arm64/geniezone/gzvm_arch_common.h | 2 ++ arch/arm64/geniezone/vm.c | 10 ++++++++++ drivers/virt/geniezone/gzvm_vm.c | 7 +++++++ include/linux/gzvm_drv.h | 3 +++ 4 files changed, 22 insertions(+) diff --git a/arch/arm64/geniezone/gzvm_arch_common.h b/arch/arm64/geniezone/gzvm_arch_common.h index 051d8f49a1df..321f5dbcd616 100644 --- a/arch/arm64/geniezone/gzvm_arch_common.h +++ b/arch/arm64/geniezone/gzvm_arch_common.h @@ -22,6 +22,7 @@ enum { GZVM_FUNC_PROBE = 12, GZVM_FUNC_ENABLE_CAP = 13, GZVM_FUNC_INFORM_EXIT = 14, + GZVM_FUNC_MEMREGION_PURPOSE = 15, NR_GZVM_FUNC, }; @@ -44,6 +45,7 @@ enum { #define MT_HVC_GZVM_PROBE GZVM_HCALL_ID(GZVM_FUNC_PROBE) #define MT_HVC_GZVM_ENABLE_CAP GZVM_HCALL_ID(GZVM_FUNC_ENABLE_CAP) #define MT_HVC_GZVM_INFORM_EXIT GZVM_HCALL_ID(GZVM_FUNC_INFORM_EXIT) +#define MT_HVC_GZVM_MEMREGION_PURPOSE GZVM_HCALL_ID(GZVM_FUNC_MEMREGION_PURPOSE) #define GIC_V3_NR_LRS 16 diff --git a/arch/arm64/geniezone/vm.c b/arch/arm64/geniezone/vm.c index 2df321f13057..17327081eb27 100644 --- a/arch/arm64/geniezone/vm.c +++ b/arch/arm64/geniezone/vm.c @@ -109,6 +109,16 @@ int gzvm_arch_destroy_vm(u16 vm_id) 0, 0, &res); } +int gzvm_arch_memregion_purpose(struct gzvm *gzvm, + struct gzvm_userspace_memory_region *mem) +{ + struct arm_smccc_res res; + + return gzvm_hypcall_wrapper(MT_HVC_GZVM_MEMREGION_PURPOSE, gzvm->vm_id, + mem->guest_phys_addr, mem->memory_size, + mem->flags, 0, 0, 0, &res); +} + static int gzvm_vm_arch_enable_cap(struct gzvm *gzvm, struct gzvm_enable_cap *cap, struct arm_smccc_res *res) diff --git a/drivers/virt/geniezone/gzvm_vm.c b/drivers/virt/geniezone/gzvm_vm.c index 60bd017e41fa..a1cf970e4c91 100644 --- a/drivers/virt/geniezone/gzvm_vm.c +++ b/drivers/virt/geniezone/gzvm_vm.c @@ -234,6 +234,7 @@ static int gzvm_vm_ioctl_set_memory_region(struct gzvm *gzvm, struct gzvm_userspace_memory_region *mem) { + int ret; struct vm_area_struct *vma; struct gzvm_memslot *memslot; unsigned long size; @@ -258,6 +259,12 @@ gzvm_vm_ioctl_set_memory_region(struct gzvm *gzvm, memslot->vma = vma; memslot->flags = mem->flags; memslot->slot_id = mem->slot; + + ret = gzvm_arch_memregion_purpose(gzvm, mem); + if (ret) { + pr_err("Failed to config memory region for the specified purpose\n"); + return -EFAULT; + } return register_memslot_addr_range(gzvm, memslot); } diff --git a/include/linux/gzvm_drv.h b/include/linux/gzvm_drv.h index d2985e4df4a0..369c3df6c0b5 100644 --- a/include/linux/gzvm_drv.h +++ b/include/linux/gzvm_drv.h @@ -141,6 +141,9 @@ void gzvm_drv_irqfd_exit(void); int gzvm_vm_irqfd_init(struct gzvm *gzvm); void gzvm_vm_irqfd_release(struct gzvm *gzvm); +int gzvm_arch_memregion_purpose(struct gzvm *gzvm, + struct gzvm_userspace_memory_region *mem); + int gzvm_init_ioeventfd(struct gzvm *gzvm); int gzvm_ioeventfd(struct gzvm *gzvm, struct gzvm_ioeventfd *args); bool gzvm_ioevent_write(struct gzvm_vcpu *vcpu, __u64 addr, int len, -- 2.18.0