From patchwork Fri Jan 5 09:13:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yan Zhao X-Patchwork-Id: 185320 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp6118138dyb; Fri, 5 Jan 2024 01:43:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IGOjY34CJSFsoEW4QFUBAEaBMiK36K3VVCGtIAEtARNj7gMO1bXQAn9W5T+o0o8nmhKeZCb X-Received: by 2002:a05:6214:1c0a:b0:680:cce8:f19d with SMTP id u10-20020a0562141c0a00b00680cce8f19dmr2385317qvc.29.1704447829326; Fri, 05 Jan 2024 01:43:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704447829; cv=none; d=google.com; s=arc-20160816; b=D7bwLFXJ2cDz+pwZr5qdcH5D1dpcdLUjY56h/FlZ6NmFIuk68uPKpKCHA0vH7vludj R5C2e8WePMooAq5qr28vr2D+4ew1reAH7Atzi1kUjeoHrk5aCPo9EbM1t30IkckuORGq O/X7iB1NUHCZgwde5OwqkXVdx/TzUvtKoH499RWIAp6SE7U73JeIOdc1NTYbsftvhK9v 0HHTAh/j7K5/hVgp61wTlY9hCkdOwTU7VFvJyP0tWJxk+biI885Rygy4U9zWpAk7CyLK ZVr47yHV8tuFPDnVt/Dusm0ieL0fZ/GcCCRK9fqQu7LpoWmKzh21Aps+vew3vQENGCo/ nGOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=bkS+UkEOxy97Jcaup9Qbm0QCUqGvKHu0ETwBqYjO/pA=; fh=YdyUGy0kKu0DsyGpr0tP9PGkupWicnl2+pb1wvQMDbw=; b=wouRabiM1luFsKg66FcC9t0k31OSieJ8YXx6p8LWj9zy9wr2o3wHeLj2WaYckGTUGw qZp1DAewrrXsdCiTWmeQ+ZujKw3PLzs4cTl46fPYQhhOaktRH/yI0dHzAn0LfNDAyPss MwG3HwdNM/o7PJzlltSK8a3oU+0c3m7id4m90PUIcsIm2DcOHl7LeZl5WEn5s6ts3unZ L1oMmeA5MwjmyKlnJF8WfAcGCGmjktCZDtFTWQGdzVwdw8L0USiEB47EXxlvGuW4n/Sz +mRzGYTJFFFXqszkCjgMe8YnM2wTthZ3LZXlNZlU6A2NV+nA7BKDh/g7QR6Xbb1ZokUC N0Zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZoIf+xOC; spf=pass (google.com: domain of linux-kernel+bounces-17674-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17674-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id c17-20020a0cf2d1000000b006807fa7c107si1357538qvm.214.2024.01.05.01.43.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 01:43:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17674-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZoIf+xOC; spf=pass (google.com: domain of linux-kernel+bounces-17674-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17674-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 235E81C22D44 for ; Fri, 5 Jan 2024 09:43:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 01E1225554; Fri, 5 Jan 2024 09:43:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ZoIf+xOC" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) (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 E622524B3A; Fri, 5 Jan 2024 09:43:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1704447790; x=1735983790; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=yLRKvEWofDO1K6stvr9i2IomNOvR/08Zs5+c4O/ibFk=; b=ZoIf+xOCUja/+xF6xyOHlmjoliHWOoFCtn9VtwXxc1nrttUKQz7wnTKt ePIytw3QiiMdUiiu6YH3SeX4krUlFxmjnwEyLwJXMZbCYgwFJcgR+eRdX FlMVlwqictEQ8be4FDr/FQE9+XGB5BwSTMPk+Nygqcx6Vk+6E1FOoqRcK aHcqxXPRM9bmjK/ef7HhTRYYpvnS3m5kVxKJp6jZneecv1mUHl59JEwE7 TP9cPzq0E0y6tYSoHkU6X2wP0VSD7jHcDDGbcv6aakpHGNxZl8TqGAPvC C47RzxDfIPf6dOxgV84xnwlXaljEd/QEc3pp39FHhXJQqnSYQ8LvWTI95 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10943"; a="401260554" X-IronPort-AV: E=Sophos;i="6.04,333,1695711600"; d="scan'208";a="401260554" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2024 01:43:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10943"; a="814920081" X-IronPort-AV: E=Sophos;i="6.04,333,1695711600"; d="scan'208";a="814920081" Received: from yzhao56-desk.sh.intel.com ([10.239.159.62]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2024 01:43:03 -0800 From: Yan Zhao To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Cc: pbonzini@redhat.com, seanjc@google.com, olvaffe@gmail.com, kevin.tian@intel.com, zhiyuan.lv@intel.com, zhenyu.z.wang@intel.com, yongwei.ma@intel.com, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org, gurchetansingh@chromium.org, kraxel@redhat.com, zzyiwei@google.com, ankita@nvidia.com, jgg@nvidia.com, alex.williamson@redhat.com, maz@kernel.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, Yan Zhao , Zhenyu Wang Subject: [PATCH 1/4] KVM: Introduce a new memslot flag KVM_MEM_NON_COHERENT_DMA Date: Fri, 5 Jan 2024 17:13:46 +0800 Message-Id: <20240105091346.24637-1-yan.y.zhao@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240105091237.24577-1-yan.y.zhao@intel.com> References: <20240105091237.24577-1-yan.y.zhao@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787243086835005067 X-GMAIL-MSGID: 1787243086835005067 Introduce a new flag KVM_MEM_NON_COHERENT_DMA to provide user space a channel to notify KVM that guest memory specified by the memslot may be accessed by noncoherent DMA devices. KVM can start honoring guest memory type for this range of guest memory in platforms that do not always honoring guest PAT, e.g. in Intel's platform. Previously, the only way to let KVM be aware of noncoherent DMA devices is through KVM device for VFIO pass-through devices, in which case, KVM is notified that all guest memory may be accessed by noncoherent DMA devices. To avoid complication, flag KVM_MEM_NON_COHERENT_DMA is not allowed to be dynamically modified for a memslot. A KVM_CAP_USER_CONFIGURE_NONCOHERENT_DMA is added to let user space know if this new memslot flag is supported in KVM. Cc: Kevin Tian Cc: Zhenyu Wang Tested-by: Yongwei Ma Signed-off-by: Yan Zhao --- include/uapi/linux/kvm.h | 2 ++ virt/kvm/kvm_main.c | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index b1f92a0edc35..4cb615e46488 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -46,6 +46,7 @@ struct kvm_userspace_memory_region2 { #define KVM_MEM_LOG_DIRTY_PAGES (1UL << 0) #define KVM_MEM_READONLY (1UL << 1) #define KVM_MEM_GUEST_MEMFD (1UL << 2) +#define KVM_MEM_NON_COHERENT_DMA (1UL << 3) /* for KVM_IRQ_LINE */ struct kvm_irq_level { @@ -1155,6 +1156,7 @@ struct kvm_ppc_resize_hpt { #define KVM_CAP_MEMORY_ATTRIBUTES 233 #define KVM_CAP_GUEST_MEMFD 234 #define KVM_CAP_VM_TYPES 235 +#define KVM_CAP_USER_CONFIGURE_NONCOHERENT_DMA 236 #ifdef KVM_CAP_IRQ_ROUTING diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index acd67fb40183..6d44dcf7322d 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1607,7 +1607,7 @@ static void kvm_replace_memslot(struct kvm *kvm, * only allows these. */ #define KVM_SET_USER_MEMORY_REGION_V1_FLAGS \ - (KVM_MEM_LOG_DIRTY_PAGES | KVM_MEM_READONLY) + (KVM_MEM_LOG_DIRTY_PAGES | KVM_MEM_READONLY | KVM_MEM_NON_COHERENT_DMA) static int check_memory_region_flags(struct kvm *kvm, const struct kvm_userspace_memory_region2 *mem) @@ -1625,6 +1625,8 @@ static int check_memory_region_flags(struct kvm *kvm, valid_flags |= KVM_MEM_READONLY; #endif + valid_flags |= KVM_MEM_NON_COHERENT_DMA; + if (mem->flags & ~valid_flags) return -EINVAL; @@ -2095,7 +2097,8 @@ int __kvm_set_memory_region(struct kvm *kvm, return -EINVAL; if ((mem->userspace_addr != old->userspace_addr) || (npages != old->npages) || - ((mem->flags ^ old->flags) & KVM_MEM_READONLY)) + ((mem->flags ^ old->flags) & + (KVM_MEM_READONLY | KVM_MEM_NON_COHERENT_DMA))) return -EINVAL; if (base_gfn != old->base_gfn) @@ -4822,6 +4825,7 @@ static int kvm_vm_ioctl_check_extension_generic(struct kvm *kvm, long arg) case KVM_CAP_USER_MEMORY2: case KVM_CAP_DESTROY_MEMORY_REGION_WORKS: case KVM_CAP_JOIN_MEMORY_REGIONS_WORKS: + case KVM_CAP_USER_CONFIGURE_NONCOHERENT_DMA: case KVM_CAP_INTERNAL_ERROR_DATA: #ifdef CONFIG_HAVE_KVM_MSI case KVM_CAP_SIGNAL_MSI: From patchwork Fri Jan 5 09:14:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yan Zhao X-Patchwork-Id: 185321 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp6118539dyb; Fri, 5 Jan 2024 01:45:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IERmGg6+d2vwuLJnDecmnUOLZJFPNN+USq2P/uxIP2qMmVXYVSVBR0coCxTuiU4gPMWJ4Gd X-Received: by 2002:a17:902:f343:b0:1d4:5b0d:6ffc with SMTP id q3-20020a170902f34300b001d45b0d6ffcmr1860664ple.61.1704447911125; Fri, 05 Jan 2024 01:45:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704447911; cv=none; d=google.com; s=arc-20160816; b=HrFHiipIsQcIwWQ8kbiDfur3b9Ys2cmbaC1fRBK3CUZPDN8P66EodsJAXi6xe9cGN0 JnyLmQxsSGqGg6ZReGzx4nbh3tAtvn82gBqOJxpCpoVV9A+YfsSB4ftlhlBYLhDtcFFo UF1AqDyR+3bZk19Q/EDN87f3CLrcbQAdGpWhKbtLwB9NZ4WOkIDdCaHrxVGa/gHiyvw0 OOaCN1rUdpnYwmfaKFwOPSQZexU+1/Sr2bHPA92qBZdiH+Ijftnftal59wDG5ZlM5oSf Hy3ejZWMW5UeAdnWPN30DeDZDsagcaGPmL6G22IHapuFbffpC54a1LHH8Ehc+AYAAxOh pgmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=ys1cm82ezrCxiRVxC6TxuiTUVNZx+BgFFqroaPWxZaQ=; fh=YdyUGy0kKu0DsyGpr0tP9PGkupWicnl2+pb1wvQMDbw=; b=QwSF1NhmCRnEvh803z59IKkWfL+1igFezpu3oksU6JZeJzRtMZi65Xr96ly3igR0qR NMzjbQIx9qf4bBiw7N9vCd2H/ey1YAT6yGKitcyNWyXgJEUvwfgdz9bpvDnpfx0YFk+l SjihfXCSHhTw1P8HeT/f4WbZotYDoeQG7bTIelez82KIhBx0ousw2p6Ba6rZ+P1zcWIt cZa68Z6pKplLY2LbWMl3bDzWO2w0G8hLjl7KJ3f87o/TNBbOMqnAJvAoMSVsBqHPNS66 vS1Lz8LjD9ussfhI3PNjzZdNxZ7l50+UwOs9MwEqNqY3AogZhrC7j2SRbvP6waEYIE1e xOug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=llifZT+L; spf=pass (google.com: domain of linux-kernel+bounces-17678-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17678-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id m5-20020a170902db0500b001d3f5ea1a72si974323plx.72.2024.01.05.01.45.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 01:45:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17678-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=llifZT+L; spf=pass (google.com: domain of linux-kernel+bounces-17678-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17678-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 1237B283D34 for ; Fri, 5 Jan 2024 09:44:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B132528DAF; Fri, 5 Jan 2024 09:44:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="llifZT+L" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (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 8210624B49; Fri, 5 Jan 2024 09:44:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1704447854; x=1735983854; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=TAQv9JJR1XqAj6tjxwKS30HsTbZYt1Z095C7qYz5bks=; b=llifZT+LT5JFklPZLtvMD6OSUyLlFZdQAxyVQwUyy85tmICkuc/cqXuU 5VbNfepjNfrHPRTF87oa3jb7W8PdQASabjwJ5IY7CQYfNXmO/BME9pRl0 Xn8+0gO72RU8Q9jlQWAiJHmgd/5A3pxROn3CqYM6fjK4GSFH4IWcbaZ0m p6g59h/OD3IHe0Vm7DjrXUiOiLIOWGZjTWN8Bc4F2hLZFr/hLjO/b6yfX iDoJ6PyobELrAtjGtVmrR07CmgrZUxqnetHRH/ipB8PiThBy5MubqRyZP bAEc0WKhFl7awk/AilCXHQ8AYrzcuvmRqFWNfR2Ts410s3BeCQvqV++d1 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10943"; a="10842964" X-IronPort-AV: E=Sophos;i="6.04,333,1695711600"; d="scan'208";a="10842964" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2024 01:44:13 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,333,1695711600"; d="scan'208";a="22458420" Received: from yzhao56-desk.sh.intel.com ([10.239.159.62]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2024 01:44:07 -0800 From: Yan Zhao To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Cc: pbonzini@redhat.com, seanjc@google.com, olvaffe@gmail.com, kevin.tian@intel.com, zhiyuan.lv@intel.com, zhenyu.z.wang@intel.com, yongwei.ma@intel.com, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org, gurchetansingh@chromium.org, kraxel@redhat.com, zzyiwei@google.com, ankita@nvidia.com, jgg@nvidia.com, alex.williamson@redhat.com, maz@kernel.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, Yan Zhao , Zhenyu Wang Subject: [PATCH 2/4] KVM: x86: Add a new param "slot" to op get_mt_mask in kvm_x86_ops Date: Fri, 5 Jan 2024 17:14:54 +0800 Message-Id: <20240105091454.24700-1-yan.y.zhao@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240105091237.24577-1-yan.y.zhao@intel.com> References: <20240105091237.24577-1-yan.y.zhao@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787243173125493866 X-GMAIL-MSGID: 1787243173125493866 Add param "slot" to op get_mt_mask in kvm_x86_ops. This is a preparation patch to later honor guest PATs for certain memslots. No functional change intended. Suggested-by: Sean Christopherson Cc: Kevin Tian Cc: Zhenyu Wang Tested-by: Yongwei Ma Signed-off-by: Yan Zhao --- arch/x86/include/asm/kvm_host.h | 3 ++- arch/x86/kvm/mmu/spte.c | 3 ++- arch/x86/kvm/vmx/vmx.c | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index a565a2e70f30..6be0d8ccff65 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1675,7 +1675,8 @@ struct kvm_x86_ops { int (*sync_pir_to_irr)(struct kvm_vcpu *vcpu); int (*set_tss_addr)(struct kvm *kvm, unsigned int addr); int (*set_identity_map_addr)(struct kvm *kvm, u64 ident_addr); - u8 (*get_mt_mask)(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio); + u8 (*get_mt_mask)(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio, + const struct kvm_memory_slot *slot); void (*load_mmu_pgd)(struct kvm_vcpu *vcpu, hpa_t root_hpa, int root_level); diff --git a/arch/x86/kvm/mmu/spte.c b/arch/x86/kvm/mmu/spte.c index 4a599130e9c9..2c3ede3f27a9 100644 --- a/arch/x86/kvm/mmu/spte.c +++ b/arch/x86/kvm/mmu/spte.c @@ -191,7 +191,8 @@ bool make_spte(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp, if (shadow_memtype_mask) spte |= static_call(kvm_x86_get_mt_mask)(vcpu, gfn, - kvm_is_mmio_pfn(pfn)); + kvm_is_mmio_pfn(pfn), + slot); if (host_writable) spte |= shadow_host_writable_mask; else diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 40e3780d73ae..85a23765e506 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -7576,7 +7576,8 @@ static int vmx_vm_init(struct kvm *kvm) return 0; } -static u8 vmx_get_mt_mask(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio) +static u8 vmx_get_mt_mask(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio, + const struct kvm_memory_slot *slot) { /* We wanted to honor guest CD/MTRR/PAT, but doing so could result in * memory aliases with conflicting memory types and sometimes MCEs. From patchwork Fri Jan 5 09:15:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yan Zhao X-Patchwork-Id: 185322 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp6118643dyb; Fri, 5 Jan 2024 01:45:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IHOYvAmUlkrCguFpK8iwUpBxaW3yf+5z36GhDqfuri1qgr3MooZVSxP/BxKue3tB7DtoVSc X-Received: by 2002:a25:a543:0:b0:db7:dad0:76c3 with SMTP id h61-20020a25a543000000b00db7dad076c3mr1776112ybi.95.1704447928320; Fri, 05 Jan 2024 01:45:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704447928; cv=none; d=google.com; s=arc-20160816; b=y4YEyv/gtEJIftwfJ0eRLRAU+zEmK9yDEmM+Efnl0CDRJNWsY6671m1ZjnzRIgtVXw ZpnMo1Di04AMdASfH15pevlZAblcnddRM8VxOfRs0InHfMeSbaR0dOaXEQF+35fANZ93 1YOBXRMndOg0240AuNUL2E+rZs5qyoyrJj9UDmXTILoQmgV0lWuswqPQ2dzYTiRvSKCv 5lhlTsFUn7BY0YaZffghAX+meEzfMvmC7mZeqO0czDJ01fgnuGbMaioyg3KHBcSl+pxt dwZc+j8r8aC6u1TzXsYXbJY+AeOzUuN83rv3nkhsQ1rugy6eB2LM5Br0/9XoSMA7qscQ fiqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=QbAUgoPW97JEnRx+QnmrZtHmf8g+iI6uxO/AlaIYCf8=; fh=YdyUGy0kKu0DsyGpr0tP9PGkupWicnl2+pb1wvQMDbw=; b=IXceenib3YmX2+FJa0dyVbOYhYMd6OP7kvUpEm3oXxYm09hysnbY7Rq2vEmjPAqP8Z TNC2QXMkVxx9iQlfR+RJTwkrIvhqCQK/7k4+JUvaWMWYXYFmNQxGFtYPPKLnXoO3B1so v6NvMbeWLT3m8FfGsXRu+FzV1ziewm9UHraXM9ObCBsTWn5Gi6WChAKNi8UD1TyWHQXW 3LT8CH6T1HXusaKeL7yAWS7GUUV1iAflTMZktPBAoPOit+QqkN4Myme+xOLudbYFdpRl 6rQU9MtWxZOexoYTe33kSflAfkWPoVxBCQXdDqCPLOPtjGzqWtVLqXP7zGhjtc+smG3h QRng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HAs4YsIO; spf=pass (google.com: domain of linux-kernel+bounces-17679-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17679-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id f3-20020a0cf3c3000000b0067f1a03a510si1397444qvm.364.2024.01.05.01.45.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 01:45:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17679-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=HAs4YsIO; spf=pass (google.com: domain of linux-kernel+bounces-17679-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17679-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 219241C20F7E for ; Fri, 5 Jan 2024 09:45:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B6DA5250FF; Fri, 5 Jan 2024 09:44:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="HAs4YsIO" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (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 B3B6424213; Fri, 5 Jan 2024 09:44:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1704447896; x=1735983896; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=dRCZ1S0CO2msFURA90luHjWFusP5YsJ6PzRmy9EYQoE=; b=HAs4YsIOHW+Pid1jcca5wKwo6ctPSfAA65outbCZccaszkdPYOsrdm76 JGPi3y3xfPR5ZMT0D2ybPTPzA8os3obluvbRs38R26EHiclsnV0AUw16D PCdmqiMhTPk86PBHIyEYhEsE7gAlURIa/SuclNem7XRCBtKzh+8OJB+w/ f/cbM8dU4HGnNzXPVQhbHXdIVLOVT2ts76277VWBgYHOy2VBOlbyncKsV 9ajEIQ3iUuTlLpFS1cTbCaxeAob5hXgiT531WiS21gVukJ2pfvccLdgiB JHRK9rqT9iPIw0hukA260h4M/3/XJeB+vnuybrPw867bJpW3UCFU7E0MP g==; X-IronPort-AV: E=McAfee;i="6600,9927,10943"; a="10959399" X-IronPort-AV: E=Sophos;i="6.04,333,1695711600"; d="scan'208";a="10959399" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2024 01:44:53 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10943"; a="784158177" X-IronPort-AV: E=Sophos;i="6.04,333,1695711600"; d="scan'208";a="784158177" Received: from yzhao56-desk.sh.intel.com ([10.239.159.62]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2024 01:44:47 -0800 From: Yan Zhao To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Cc: pbonzini@redhat.com, seanjc@google.com, olvaffe@gmail.com, kevin.tian@intel.com, zhiyuan.lv@intel.com, zhenyu.z.wang@intel.com, yongwei.ma@intel.com, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org, gurchetansingh@chromium.org, kraxel@redhat.com, zzyiwei@google.com, ankita@nvidia.com, jgg@nvidia.com, alex.williamson@redhat.com, maz@kernel.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, Yan Zhao , Zhenyu Wang Subject: [PATCH 3/4] KVM: VMX: Honor guest PATs for memslots of flag KVM_MEM_NON_COHERENT_DMA Date: Fri, 5 Jan 2024 17:15:35 +0800 Message-Id: <20240105091535.24760-1-yan.y.zhao@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240105091237.24577-1-yan.y.zhao@intel.com> References: <20240105091237.24577-1-yan.y.zhao@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787243190683117766 X-GMAIL-MSGID: 1787243190683117766 Honor guest PATs in the range of memslots of flag KVM_MEM_NON_COHERENT_DMA set no matter the value of noncoherent dma count. Just honoring guest PATs (without honoring guest MTRRs) for memslots of flag KVM_MEM_NON_COHERENT_DMA is because - guest OS will ensure no page aliasing issue in guest side by honoring guest MTRRs in guest page table. Combinations like guest MTRR=WC or UC, guest PAT = WB is not allowed. (at least in Linux, see pat_x_mtrr_type()). - guest device driver programs device hardware according to guest PATs in modern platforms. Besides, we don't break down an EPT huge page if guest MTRRs in its range are not consistent, because - guest should have chosen correct guest PATs according to guest MTRRs. - in normal platforms, small guest pages with different PATs must correspond to different TLBs though they are mapped in a huge page in EPT. However, one condition may not be supported well by honoring guest PAT alone -- when guest MTRR=WC, guest PAT=UC-. By honoring guest MTRRs+PATs, the effective memory type is WC; while by honoring guest PATs alone, the effective memory type is UC. But it's arguable to support such a usage. Suggested-by: Sean Christopherson Cc: Kevin Tian Cc: Zhenyu Wang Tested-by: Yongwei Ma Signed-off-by: Yan Zhao --- arch/x86/kvm/vmx/vmx.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 85a23765e506..99f22589fa6d 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -7600,6 +7600,9 @@ static u8 vmx_get_mt_mask(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio, if (is_mmio) return MTRR_TYPE_UNCACHABLE << VMX_EPT_MT_EPTE_SHIFT; + if (slot->flags & KVM_MEM_NON_COHERENT_DMA) + return MTRR_TYPE_WRBACK << VMX_EPT_MT_EPTE_SHIFT; + if (!kvm_arch_has_noncoherent_dma(vcpu->kvm)) return (MTRR_TYPE_WRBACK << VMX_EPT_MT_EPTE_SHIFT) | VMX_EPT_IPAT_BIT; From patchwork Fri Jan 5 09:16:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yan Zhao X-Patchwork-Id: 185323 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp6118875dyb; Fri, 5 Jan 2024 01:46:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IHKV+LilwNdjqQzJItwtKbR28DoJzDaNTVI2R0XS1bBL7jMO2xJlJFgtN/ITFIUf0i1awTX X-Received: by 2002:a05:6830:ec4:b0:6dc:2549:3e6c with SMTP id dq4-20020a0568300ec400b006dc25493e6cmr1917855otb.15.1704447968986; Fri, 05 Jan 2024 01:46:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704447968; cv=none; d=google.com; s=arc-20160816; b=Zg0fQE261CUvrgS8CCftFnwKHBhKz/22sP3ijXP68E294ZQYrXmewZaYD/92zojj2l M4wx5nZTQDP80lw6Tg0gqboQ92uMcFnhzvKViAnUwslImkK/vD6Lf+1aB/lEIqNMlvOs Cr+9CO8P/18gqerbWUjEGym/2TMpzTr4fvGfwyjMB4UwJA3p0kerZWV6TIszc8XlawjZ K5ezZY+5nqF9ga0GCxTAGIARicle4slFpoOegjwJjYTSz74lVwNkOkH2athN8XzHKsxL /rEPXVb6l+GHAuCRFyyI4lN0jAVCSfmOD1GZRBDoC26IabM+1urW54KXkw0RK3m16Xsp P/7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=szf+rwTJHrFVbPVxjfEiR3qSFR2jeAJjGD32sAPWQKk=; fh=7+Mp40O15i8480Y3Lx1xUfrNoWlx4dq3oRO8LaTgnuQ=; b=K5hRY6NW+LcYO1Llcd1N+je/4t7+xyIGyxhuE880CdO3zZWyvpJ/htDOsbLrCcmSKv 7ZJhCQV+xcxagmY5VevTSKATW7vAVOyPxgjJtWCfceC2h+zs4mJHtWaB5ojP0CKlbQBz YcEoEOnISOathV8etTJauivusdC91Bm7bJgp2Kj6OpFLlz6qa6bH0e16TeVImGBkwzbu bgkiwKjhVXAL/erpIwdEUbTkeiuHyGtJYhAeo9dAgCikydzvTmWWWF7oMO5T8nlZCgjz Fo8SeHxz5FNM0JR3ykyq00p/+9lKg/xyGZLlLNJAJf4SQu3HbuF+NR+0aBYDDGc6Nsh8 BHGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fnuyo02r; spf=pass (google.com: domain of linux-kernel+bounces-17682-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17682-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id m15-20020a6562cf000000b005ca4098bf5fsi1011420pgv.620.2024.01.05.01.46.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 01:46:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17682-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=fnuyo02r; spf=pass (google.com: domain of linux-kernel+bounces-17682-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17682-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 06815B213D8 for ; Fri, 5 Jan 2024 09:46:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 91AF524B5D; Fri, 5 Jan 2024 09:45:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="fnuyo02r" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (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 A8FE8249E9; Fri, 5 Jan 2024 09:45:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1704447943; x=1735983943; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=Ipngyt99PQBot25YTtxsZ8y9PD4Q1alyU7StkGQNfLY=; b=fnuyo02rSKwwPWrsZFROs7v/XHn9dr5YDWhie/bbv5+7sNUQx1Kx9e6t 3pLdO95MBos9DmdsTw9bWomhj2XsM4LXWvOp4ESTBClk0nPmgXyZEmYVB WsqbHUHC5qjLzn4RJAjG/+1rFx6kjrqfKp2cafqu797EewAd5/VZQ0bHH CdVekDRYa96g6968LeqNeZEdIBIWn9vizSVeuNERsZEECkbH5rNvkhax+ 98yPQ0dNV7CPZe/p9plKBOir7VhYDbSlHeSkll9bjjLr1wChGshvdFwYh /t3CV6Oxx1nD7ok1wy4E0WJqIweTnd3o1nmexXLUkHq/89ACpKIAPKsFt w==; X-IronPort-AV: E=McAfee;i="6600,9927,10943"; a="10959501" X-IronPort-AV: E=Sophos;i="6.04,333,1695711600"; d="scan'208";a="10959501" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2024 01:45:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10943"; a="784158335" X-IronPort-AV: E=Sophos;i="6.04,333,1695711600"; d="scan'208";a="784158335" Received: from yzhao56-desk.sh.intel.com ([10.239.159.62]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jan 2024 01:45:36 -0800 From: Yan Zhao To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Cc: pbonzini@redhat.com, seanjc@google.com, olvaffe@gmail.com, kevin.tian@intel.com, zhiyuan.lv@intel.com, zhenyu.z.wang@intel.com, yongwei.ma@intel.com, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org, gurchetansingh@chromium.org, kraxel@redhat.com, zzyiwei@google.com, ankita@nvidia.com, jgg@nvidia.com, alex.williamson@redhat.com, maz@kernel.org, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, Yan Zhao Subject: [PATCH 4/4] KVM: selftests: Set KVM_MEM_NON_COHERENT_DMA as a supported memslot flag Date: Fri, 5 Jan 2024 17:16:24 +0800 Message-Id: <20240105091624.24822-1-yan.y.zhao@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240105091237.24577-1-yan.y.zhao@intel.com> References: <20240105091237.24577-1-yan.y.zhao@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787243233697025109 X-GMAIL-MSGID: 1787243233697025109 Update test_invalid_memory_region_flags() to treat KVM_MEM_NON_COHERENT_DMA as a supported memslot flag. Signed-off-by: Yan Zhao --- tools/testing/selftests/kvm/set_memory_region_test.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/testing/selftests/kvm/set_memory_region_test.c b/tools/testing/selftests/kvm/set_memory_region_test.c index 075b80dbe237..2d6f961734db 100644 --- a/tools/testing/selftests/kvm/set_memory_region_test.c +++ b/tools/testing/selftests/kvm/set_memory_region_test.c @@ -335,6 +335,9 @@ static void test_invalid_memory_region_flags(void) #if defined __aarch64__ || defined __x86_64__ supported_flags |= KVM_MEM_READONLY; + + if (kvm_has_cap(KVM_CAP_USER_CONFIGURE_NONCOHERENT_DMA)) + supported_flags |= KVM_MEM_NON_COHERENT_DMA; #endif #ifdef __x86_64__