Received: by 2002:ab2:7407:0:b0:1f4:b336:87c4 with SMTP id e7csp263400lqn; Thu, 11 Apr 2024 23:59:35 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVfUsxea+tR4CCRRNSWW2C0qxQs0zNj7KgPov+b2Gjf+rzUsM0QgfNbEhrKuNxCup5GzxWBXiYWevnXiy+ScuTgfjaVf2wMZ7rXeLf+8Q== X-Google-Smtp-Source: AGHT+IG/OfRPRiUBom72aW5I7aWU7pNIG5X3v02XnnWi/aYOgT5nax680m1Pi9HheVtqshRXq7Ru X-Received: by 2002:a05:6a20:7343:b0:1a9:9ccf:974 with SMTP id v3-20020a056a20734300b001a99ccf0974mr2006429pzc.6.1712905175065; Thu, 11 Apr 2024 23:59:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712905175; cv=pass; d=google.com; s=arc-20160816; b=VoBQhoxZhP6DZV9q3Sg3eSd7GnZnC1kPWvX/9gaOJLDgsoPQ4d6sFh9QWMaT8zHzOT iZrri8cEcaZ8igOI6j4xw03qfoAxs3vlShNzx6zo/57kbB8rJq+ZDmto/d8w8B+qgON9 /qdXIan+XhYy1X8GCoRlRhPZFLyKcYAYVX87f4kUvyUV6AjOKvzAL7xf5yf8ForMC0P6 Jen96Mjtw+IsFv4OG2wp2NsVR2cNLVMHq9BRmdBW0LJMCDvUh/StAmuaRGSu8sf7ayO4 vXwIJMx+7ZEBN2iNExdv0/arO4ZBEEf5dVcVkp2rACsfVEU1FJwExRPDbTSDJ+DHw/l9 KA4Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Sf44/j3w3wHE2SJEbkekN47eKbu4WkVyz5aJcUxKfkI=; fh=N0E7aQANPyt0+K/4JzHblmSjZpqEZzwskGUWRTyqEws=; b=OgoWvfJJjK6GZP+uxPzmr4+vwwxnOvoui2CiML2+K1JE2Gvb2ZZ38iXsY3A/qFmdqh qanMPCjyumCxdwszplFkkQcHA8mFT2/r4PJuI/2zCsmdp+Jf3BTSj5W/z3BGGWL8PX/L nC0ohzibPDv4rE00OUdQVgeEm6SmD9uMwpAw5Alkh1eGQijmApS5HSD84Yq8i7hFgSZa b0YoOEZsQ8OQgHJXQXTMROXt5INpFOE61WeVB9/VPL5YxzYyu2Pl7esP/Wt8kNLvhgAm eerGY7uFw0WOSq1g6MLH+nJws7b2K6tUAxfqLJpHZXtaFitDDyVIKKJ+hglxfsbUJbdg IeYQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=cZqjZMnV; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-142079-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142079-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id l8-20020a056a00140800b006e6f6dd1735si2860925pfu.371.2024.04.11.23.59.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 23:59:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-142079-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=cZqjZMnV; arc=pass (i=1 spf=pass spfdomain=mediatek.com dkim=pass dkdomain=mediatek.com dmarc=pass fromdomain=mediatek.com); spf=pass (google.com: domain of linux-kernel+bounces-142079-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-142079-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 05C5E285B40 for ; Fri, 12 Apr 2024 06:58:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 64F594CE0F; Fri, 12 Apr 2024 06:57:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="cZqjZMnV" Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24C0645BF6; Fri, 12 Apr 2024 06:57:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.61.82.184 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712905075; cv=none; b=i/ZIASASICfRBxRgAPlV7VKdeUvoj2YTHB+ehWyowCDEaW4qpidJVJSC4GEUatU7EO0X+evC7KcDclX7R+RA7BRmMgKD7Vy+PO9rTsw181rppXof2GrnVgvpRjHESy5J4PiIavtJycUzTam4VLir9OiaG91f+Q6twbScAmp504A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712905075; c=relaxed/simple; bh=kk1BqshOMRobheUuNWZvJ3R+fFfwvIPqmeFsMCCh8Og=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IbSbm7bZ1u6RaneD7Y28QzbYRRZIeq5Ghy6VInxfPFswEVTXyJLNNEs8bBRFWS8hAJQmNReGX0tfWPTefej3CLfn1s6cRyTRk+L+OB/J084nzLEQk9iby1OtqM95Mrv2fRBCfRK3kxTr/aiofWs856VPh5p1VQfsfERIRLnEZCw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=cZqjZMnV; arc=none smtp.client-ip=210.61.82.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com X-UUID: f8cda46cf89911ee935d6952f98a51a9-20240412 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=Sf44/j3w3wHE2SJEbkekN47eKbu4WkVyz5aJcUxKfkI=; b=cZqjZMnVipQhMXOCT+dduWm/QtiRWnqwTHcG47JWJ0P4nbFGX9gTRdN/fmSGWHYom1s6a+J+GP6GQ6tiV6reZZCAn5WOcfzPM5/t1Q+DfHt+m585uqad7qQe/vrJugYfY/TBW7G/i7E2ga+8GAZUEnRYwo6GcEEb5AH4WeRaZ7Y=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.37,REQID:ae034126-7544-4ce2-8d57-337950a179fd,IP:0,U RL:0,TC:0,Content:-25,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-25 X-CID-META: VersionHash:6f543d0,CLOUDID:849a7e91-e2c0-40b0-a8fe-7c7e47299109,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:11|1,File:nil,RT:nil,Bulk:nil,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_SNR,TF_CID_SPAM_ULN X-UUID: f8cda46cf89911ee935d6952f98a51a9-20240412 Received: from mtkmbs09n2.mediatek.inc [(172.21.101.94)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1566461187; Fri, 12 Apr 2024 14:57:48 +0800 Received: from mtkmbs13n1.mediatek.inc (172.21.101.193) by mtkmbs11n1.mediatek.inc (172.21.101.185) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Fri, 12 Apr 2024 14:57:47 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs13n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Fri, 12 Apr 2024 14:57:46 +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 , Richard Cochran , Matthias Brugger , AngeloGioacchino Del Regno CC: , , , , , , David Bradil , Trilok Soni , My Chuang , Shawn Hsiao , PeiLun Suei , Liju Chen , Willix Yeh , Kevenny Hsieh Subject: [PATCH v10 13/21] virt: geniezone: Add memory region support Date: Fri, 12 Apr 2024 14:57:10 +0800 Message-ID: <20240412065718.29105-14-yi-de.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20240412065718.29105-1-yi-de.wu@mediatek.com> References: <20240412065718.29105-1-yi-de.wu@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain X-MTK: N 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/soc/mediatek/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 d4b49a4b283a..dabd11438e94 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 84d763032f60..026684c601a8 100644 --- a/arch/arm64/geniezone/vm.c +++ b/arch/arm64/geniezone/vm.c @@ -146,6 +146,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 dbd83e2358c9..f6846602dec5 100644 --- a/drivers/virt/geniezone/gzvm_vm.c +++ b/drivers/virt/geniezone/gzvm_vm.c @@ -78,6 +78,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; @@ -101,6 +102,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/soc/mediatek/gzvm_drv.h b/include/linux/soc/mediatek/gzvm_drv.h index e459dfa681a4..1c1927b642f6 100644 --- a/include/linux/soc/mediatek/gzvm_drv.h +++ b/include/linux/soc/mediatek/gzvm_drv.h @@ -177,6 +177,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