From patchwork Mon Feb 8 03:20:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haibo Xu X-Patchwork-Id: 378517 Delivered-To: patch@linaro.org Received: by 2002:a02:b18a:0:0:0:0:0 with SMTP id t10csp4344011jah; Sun, 7 Feb 2021 19:53:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJyBVc/Sm9dxgxE8KP43fil6c/CBEOXjbfjVdz+1/psUKzABBwDqog20I0yRPLzjNgrq6F3/ X-Received: by 2002:a25:9d01:: with SMTP id i1mr22410461ybp.359.1612756415704; Sun, 07 Feb 2021 19:53:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612756415; cv=none; d=google.com; s=arc-20160816; b=tiocstpF1qLLtDdePw7lIDhF1E5bmClm7duh1WMr7olRbJApB06w44QaArnmPVrOUo FCe8o+Jd28N4YIdb2jKgKjwTJtcpxomAmAaQs52kIHIQh765oDR7a+RMKfZQ4ZqT85Ry lQTXjWQ+Vb30cd9gfJdCwmLtdGIhJc7/xA2xKD7/IfP1Ry6JXXZLtVig1cPSMg9uM2Z4 qRJJjQaF6XJbe0pm3GSCIYJ9pDKF/ynnYkBtPMlzIK3yplNzIfiJp2hm4INJrQJv8qau Rnghrc0V59zuDsi+qdaUBJyzXMYr2EyMGm3QBWVpGfgFvqWJiimOabbGw4ath1bQqXZu GtUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=MGfxbUHNHVC0PoO0wrBnW/QIqjiqRvvXdfo0luDm70M=; b=ZA0OQv1QNx1UipBZxXYR8AjjBt1Z4KTaLSoU7ELIsACDxWaB9/Nq1x1D9utU4rjGt7 XX8emjcprm4FhiBFhNhVp9aznOTY5qFNjcHBetoBwZFTTSnfPHb7jS8exCZIEvPAgscW bWNpmPq3WUGNMbfkZtwHnJqm5Y45UmarVocWVhan4bmtIPZmXR0IzqJXyGagcOXKRezN AI+GaQTNlYG1yxK521lum0mDAry7hI4YwQNohB/cH87jlQsJvCGLCH/NQcsoWtBeX3aH PPiL9zPnvkPwvFA+zTaD4KFh/4F+wEkqTzZz9SG7+jUv8HXUT0HpKU+Pwcac/G4zE32d L9dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=WlsvuiBD; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id r3si16901732ybg.132.2021.02.07.19.53.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 07 Feb 2021 19:53:35 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=WlsvuiBD; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:46884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l8xcF-0001NN-63 for patch@linaro.org; Sun, 07 Feb 2021 22:53:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35616) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l8x6G-0007gD-W2 for qemu-devel@nongnu.org; Sun, 07 Feb 2021 22:20:33 -0500 Received: from mail-il1-x130.google.com ([2607:f8b0:4864:20::130]:34665) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l8x6C-0001iY-I5 for qemu-devel@nongnu.org; Sun, 07 Feb 2021 22:20:32 -0500 Received: by mail-il1-x130.google.com with SMTP id q9so11496652ilo.1 for ; Sun, 07 Feb 2021 19:20:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MGfxbUHNHVC0PoO0wrBnW/QIqjiqRvvXdfo0luDm70M=; b=WlsvuiBDhRnYgnyXvcFFkNMd3K6x3ERkoNTdMoy6ODU8KnCwknS4rSCthu+gyXUs06 vlKraVxJMEGyLt01ipgwpt8aj1oPd63SY4SN8zg6/AhWpMFpFxzGjZ3T4c1NlLA6xlC9 gjrKlTizOG3jZ/n/SVvreJexpsgCXG/aRZayVVzfZGqiIUzch1hWyrHknfxPImeNkKFQ oasK2dkhgj8rfCJt2LOc0+1NIhLLjPK/lQt8exHEAcHI+pXr/hIMOnZDQ0QgtHY+Khu6 1u28TbbDeM63iGjxPCUyjc4/RJxARQwuLCzDihTbE1KpOGMNl2H6P2m9lHNwiTMSnzqF Jg9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MGfxbUHNHVC0PoO0wrBnW/QIqjiqRvvXdfo0luDm70M=; b=Tx1cUDxL08a9AkfoUiUTjm/sOV6njmZAGE159o79cxP7RxqfLa6Q7P0ldMgcYRFVfK ttYjEiA8BZwmHNw1S/xJfbi4xOeoWvcsjdbOc7Z7jKixILyyXaFw1ft86YZm53o8PIjh WUH41ej8Y7s8TWN7ZKzsiRJPzhP4z7oHW1eKali9EBx4BlNV1QUaH/uduGPCL5T7GXPp +dWjbANyZTk1s130DCJz9fwuRsG3bKDcL0WxGoy3+ZbNbvefaLPXFGnu8gf6wdn9/ohB Dsmb48BzcKRfZiXRra7uqjKSwMPc13BOtgL39QudcTtTWDPCh6tYnq7hpMLWCztaeyHN /P1w== X-Gm-Message-State: AOAM532IjHcYeKCsaVNSXVx6fzJG02KzVNDuQB0vD2rAZskCwmxsLjUe ZtcOwLX2DrclF3eKEcjTzK/X X-Received: by 2002:a92:c56b:: with SMTP id b11mr14584456ilj.167.1612754426953; Sun, 07 Feb 2021 19:20:26 -0800 (PST) Received: from localhost.localdomain ([147.75.106.138]) by smtp.gmail.com with ESMTPSA id o8sm8022965ilu.55.2021.02.07.19.20.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Feb 2021 19:20:26 -0800 (PST) From: Haibo Xu To: drjones@redhat.com, richard.henderson@linaro.org Subject: [RFC PATCH 1/5] Update Linux headers with new MTE support Date: Mon, 8 Feb 2021 03:20:02 +0000 Message-Id: <432d5c0c6fb79e29f2e7aa4730cf4339d3d858f0.1612747873.git.haibo.xu@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::130; envelope-from=haibo.xu@linaro.org; helo=mail-il1-x130.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, qemu-arm@nongnu.org, philmd@redhat.com, qemu-devel@nongnu.org, Haibo Xu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Haibo Xu --- linux-headers/linux/kvm.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) -- 2.17.1 diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h index 020b62a619..6a291a9a35 100644 --- a/linux-headers/linux/kvm.h +++ b/linux-headers/linux/kvm.h @@ -1056,6 +1056,7 @@ struct kvm_ppc_resize_hpt { #define KVM_CAP_ENFORCE_PV_FEATURE_CPUID 190 #define KVM_CAP_SYS_HYPERV_CPUID 191 #define KVM_CAP_DIRTY_LOG_RING 192 +#define KVM_CAP_ARM_MTE 193 #ifdef KVM_CAP_IRQ_ROUTING @@ -1241,6 +1242,19 @@ struct kvm_arm_device_addr { __u64 addr; }; +#define KVM_ARM_TAGS_TO_GUEST 0 +#define KVM_ARM_TAGS_FROM_GUEST 1 + +struct kvm_arm_copy_mte_tags { + __u64 guest_ipa; + __u64 length; + union { + void *addr; + __u64 padding; + }; + __u64 flags; +}; + /* * Device control API, available with KVM_CAP_DEVICE_CTRL */ @@ -1396,6 +1410,7 @@ struct kvm_s390_ucas_mapping { /* Available with KVM_CAP_PMU_EVENT_FILTER */ #define KVM_SET_PMU_EVENT_FILTER _IOW(KVMIO, 0xb2, struct kvm_pmu_event_filter) #define KVM_PPC_SVM_OFF _IO(KVMIO, 0xb3) +#define KVM_ARM_MTE_COPY_TAGS _IOR(KVMIO, 0xb4, struct kvm_arm_copy_mte_tags) /* ioctl for vm fd */ #define KVM_CREATE_DEVICE _IOWR(KVMIO, 0xe0, struct kvm_create_device) From patchwork Mon Feb 8 03:20:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haibo Xu X-Patchwork-Id: 378521 Delivered-To: patch@linaro.org Received: by 2002:a02:b18a:0:0:0:0:0 with SMTP id t10csp4345538jah; Sun, 7 Feb 2021 19:57:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJyo4ddsmFHsXiUegSpd4CnRa6fVTfAtOvvO5KYDODl5ZaS9ICHDOR6Df2cwL9mfBszhs9O0 X-Received: by 2002:a25:858e:: with SMTP id x14mr23987283ybk.257.1612756635712; Sun, 07 Feb 2021 19:57:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612756635; cv=none; d=google.com; s=arc-20160816; b=A7qF2hP4bpmuUBLivtlJtkYp+N0U48CO/LnPgYAxXBM26jnayU4ZYeXSGkLACyOtUI Kt1UEYrXArf8E1tpLr/hseekjWD64YBnMjbbmEFp9To9WOU1GKBRPSzrvh/jKccK7rKC ga1Fy4UdoLP7lmFRY6Qk8kquQISySA9HrlQztJmq7mSKLKhadHm5cWXS80nvf6Ba8Wni nFW94MSMn2lJGjNQU5DqFK53xDrGaFa1YF65QXHWQ+V/50FtHtrLX9jlpsNg894VcBND xiaL7+G/F8vAPtrK8/Mkf5SF96S8SYV/Iv7Ol8SIFz3e9TD6O73qeGo3T4sp8ni89gDj Dciw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=I7kX52+i6GRyy+3lYBjqHTFyTQeUgleV90lSPDfFuBI=; b=EFHvT9a7NZQ1EixAv7bdrCgaRRvMGZ6dm2CvAYpcjfm87xEsZu/kFrnIypkYUJ/IJs ONf0LzoMlWbmVVRXIXyiC8y4pn1M9JKfzXbD3RrWIWo7yqeP/Gf4gMYG6Ai4aqA0/I37 3KNOj8lTmpxdUnSklPY7vxcB1mAYUtczlaYvcIHEqFf0pGIi+b6H2OzMeE2fRcDZBznu r8GFhaltIsDzZmO1Vk1PzJO6h8H2KlHFUM2w+GtHTqGXjWJf2PMEV4Q2VCz3coX28TNk vGwnJGXNU3KFP9uten13dIV0GtQShCqog5g3R8kXKOKnzWQR15eZ+XH96ZucyrZLUHul FHgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=qxtw6Swo; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id e3si16659412ybi.121.2021.02.07.19.57.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 07 Feb 2021 19:57:15 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=qxtw6Swo; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:58420 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l8xfn-0006Bs-6N for patch@linaro.org; Sun, 07 Feb 2021 22:57:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35642) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l8x6I-0007in-6i for qemu-devel@nongnu.org; Sun, 07 Feb 2021 22:20:34 -0500 Received: from mail-il1-x12b.google.com ([2607:f8b0:4864:20::12b]:46557) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l8x6C-0001ij-Pl for qemu-devel@nongnu.org; Sun, 07 Feb 2021 22:20:33 -0500 Received: by mail-il1-x12b.google.com with SMTP id m20so11450513ilj.13 for ; Sun, 07 Feb 2021 19:20:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=I7kX52+i6GRyy+3lYBjqHTFyTQeUgleV90lSPDfFuBI=; b=qxtw6SwooIdn9ov3wbboEkGG84GD/5rSi1t5TkmrylFDjzUCD9rOmJ2KRjR4lXdiUq 7j05tdtRIcDmVjQnqYaVM3uPil+UwKZI424v2Y4q1idO+6HCXKz3Eh9X0RikaQ/RAoTg hT70RTMvlL/tW816z5z8v1uPSAb0GY/kHoXCq+BH8WWRfvsuXs1tWdso2N9amh07tlRd 3wvSOxjGLJZ912SRUe+FmBYjEPmwpxeSSNa2spdOP7OAbph/3bAXb5fsFTN6QrTqed+T Zv0g7GMEFAfGa1cGzRjosPpGAi6gc46aK+7GLXE1n4QvgC1i3yMAACjH4LfxUJDjionZ WE+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=I7kX52+i6GRyy+3lYBjqHTFyTQeUgleV90lSPDfFuBI=; b=Z1ONplYF1IiNpz50sMXKLcGcVQG+Pty56rgaD6fCSnTwGqhC9v3jmLsFbuuPOlpnmi VQE4ZF8KOdxARnkEARjevpIaJHzarYd2vMWZnueXL0/hWg9116nPSL/dAymhkNrBTf8X jUuV/JBxFPl9//ebJtwDJ80RV8vr4mEMhXYEIXeKosh9o5DGOuVpbk14OI2aAdIley2k H9HzTLMg3SHsVM4E9dycA+pqnyKLhbe4ARAKrVBd7m19mJAE6kOnCj3lljq1O9fmIpDO oZED3QckMRd0KlYT+UQ43WsyypT0XR9NsSHCy9U4Eqm97aVsukEUhgK+hMoIQpHhp2mJ eRqA== X-Gm-Message-State: AOAM531ynMU8MAkp2bVFa8ayJDIpD0xl4yUEETimZ15MJ31jO1XQTJSZ VS06N0FCPh9mvv/bKhI/sOQl X-Received: by 2002:a05:6e02:1343:: with SMTP id k3mr13906775ilr.102.1612754427727; Sun, 07 Feb 2021 19:20:27 -0800 (PST) Received: from localhost.localdomain ([147.75.106.138]) by smtp.gmail.com with ESMTPSA id o8sm8022965ilu.55.2021.02.07.19.20.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Feb 2021 19:20:27 -0800 (PST) From: Haibo Xu To: drjones@redhat.com, richard.henderson@linaro.org Subject: [RFC PATCH 2/5] Add basic MTE support to KVM guest Date: Mon, 8 Feb 2021 03:20:03 +0000 Message-Id: <9c4507258ffe9cea4aeb5e19ef8475cb65230c3d.1612747873.git.haibo.xu@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::12b; envelope-from=haibo.xu@linaro.org; helo=mail-il1-x12b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, qemu-arm@nongnu.org, philmd@redhat.com, qemu-devel@nongnu.org, Haibo Xu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Enable the virt machine feature "mte" to work with KVM guest. This feature is still hiden from the user in this patch, and will be available in a later patch. Signed-off-by: Haibo Xu --- hw/arm/virt.c | 22 +++++++++++----------- target/arm/cpu.c | 2 +- target/arm/kvm.c | 9 +++++++++ target/arm/kvm64.c | 7 +++++++ 4 files changed, 28 insertions(+), 12 deletions(-) -- 2.17.1 diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 399da73454..623d5e9397 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -1974,18 +1974,18 @@ static void machvirt_init(MachineState *machine) } if (vms->mte) { + /* + * The property exists only if MemTag is supported. + * If it is, we must allocate the ram to back that up. + */ + if (!object_property_find(cpuobj, "tag-memory")) { + error_report("MTE requested, but not supported " + "by the guest CPU"); + exit(1); + } + /* Create the memory region only once, but link to all cpus. */ - if (!tag_sysmem) { - /* - * The property exists only if MemTag is supported. - * If it is, we must allocate the ram to back that up. - */ - if (!object_property_find(cpuobj, "tag-memory")) { - error_report("MTE requested, but not supported " - "by the guest CPU"); - exit(1); - } - + if (!tag_sysmem && !kvm_enabled()) { tag_sysmem = g_new(MemoryRegion, 1); memory_region_init(tag_sysmem, OBJECT(machine), "tag-memory", UINT64_MAX / 32); diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 40142ac141..50f3223944 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -1831,7 +1831,7 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) cpu->secure_memory); } - if (cpu->tag_memory != NULL) { + if (cpu->tag_memory != NULL && !kvm_enabled()) { cpu_address_space_init(cs, ARMASIdx_TagNS, "cpu-tag-memory", cpu->tag_memory); if (has_secure) { diff --git a/target/arm/kvm.c b/target/arm/kvm.c index ffe186de8d..33630b2b70 100644 --- a/target/arm/kvm.c +++ b/target/arm/kvm.c @@ -32,6 +32,7 @@ #include "hw/boards.h" #include "hw/irq.h" #include "qemu/log.h" +#include "hw/arm/virt.h" const KVMCapabilityInfo kvm_arch_required_capabilities[] = { KVM_CAP_LAST_INFO @@ -272,6 +273,14 @@ int kvm_arch_init(MachineState *ms, KVMState *s) } } + if (kvm_check_extension(s, KVM_CAP_ARM_MTE) && + object_dynamic_cast(OBJECT(ms), TYPE_VIRT_MACHINE) && + VIRT_MACHINE(ms)->mte) { + if (kvm_vm_enable_cap(s, KVM_CAP_ARM_MTE, 0)) { + error_report("Failed to enable KVM_CAP_ARM_MTE cap"); + } + } + return ret; } diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c index 3c37fc4fb6..23f34034db 100644 --- a/target/arm/kvm64.c +++ b/target/arm/kvm64.c @@ -500,6 +500,7 @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf) */ int fdarray[3]; bool sve_supported; + bool mte_supported; uint64_t features = 0; uint64_t t; int err; @@ -646,6 +647,7 @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf) } sve_supported = ioctl(fdarray[0], KVM_CHECK_EXTENSION, KVM_CAP_ARM_SVE) > 0; + mte_supported = ioctl(fdarray[0], KVM_CHECK_EXTENSION, KVM_CAP_ARM_MTE) > 0; kvm_arm_destroy_scratch_host_vcpu(fdarray); @@ -659,6 +661,11 @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf) t = FIELD_DP64(t, ID_AA64PFR0, SVE, 1); ahcf->isar.id_aa64pfr0 = t; } + if (mte_supported) { + t = ahcf->isar.id_aa64pfr1; + t = FIELD_DP64(t, ID_AA64PFR1, MTE, 2); + ahcf->isar.id_aa64pfr1 = t; + } /* * We can assume any KVM supporting CPU is at least a v8 From patchwork Mon Feb 8 03:20:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haibo Xu X-Patchwork-Id: 378519 Delivered-To: patch@linaro.org Received: by 2002:a02:b18a:0:0:0:0:0 with SMTP id t10csp4344700jah; Sun, 7 Feb 2021 19:55:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJzWBLhAihXgiTQd4p5KQ+lqz7y+4wRpGYOWaKVlKaGcGmJHm5GIJu8tDDaXM0bUVvXApKwf X-Received: by 2002:a25:9a04:: with SMTP id x4mr24209882ybn.184.1612756513736; Sun, 07 Feb 2021 19:55:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612756513; cv=none; d=google.com; s=arc-20160816; b=HEL28a5W74fr2VyuZ21isHU+NcGCli5qRadQOvG0xHeEpiVr0XoVVhGGMA6mjXNLG3 xlDJlaBvbP2VHam65V3bTJp6TiBaFqfwCu5bU13qR7vT05t1pcGRf47Jy5rOheHYfiMT uqwonqK7sTuFX2TwHmyN0LHY2oDrQ9TtckCD0fV/2EfwqMlNncqhs93kBzhAnNNx53zf 5OS0K2rI0Jg2iHfP5GfIV4yRuT/4cQY52ojMJoGj3nb4fScIsFnpXl7Dgli9KC/2mF76 KrR+XOIUgSC81PfxoED91/3qg0dClpFdgvjT8c3Rr43hGR4BiPR9FmjQLtqun9TXlzGQ O19g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=o0Vd6bwYd4gneYtpxWheq/+EF/MLp77aqunUp/r0WeM=; b=L3eCFUVrMZJKPzN5G9wx1f1ZcbcgnITMfyKJyZCmtW+go83XDob4BnMpV+wJXwTnc5 PEFf0nXcRaU2gdhVTU2/1/rX/Tvvx+yIkXf2tiEFB6AstNJ/qrs16KrvcPDCswN3Ti++ A8361dJN1pcjb5B/oLPGFqt+h6m1EMKMLeNjHeJCqb6BlO4Kvwi7xZhiAYWYw7ciLu9l OqlR/1Lr9aQQKl3fU6FYEXgWSApyjCu/CR+NlD5V7i5w39P0Ttu+TFu1aQ+Cua0ZyRS9 vKU4Shyi8hF9+cVtXADtPfev82V6sZIfmXoGqmGKNPcA6uVpcWTi0GzV0iDykOxYva6P PAQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=WJPJFFmC; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id y198si6767400ybe.83.2021.02.07.19.55.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 07 Feb 2021 19:55:13 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=WJPJFFmC; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:53574 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l8xdp-00048n-8E for patch@linaro.org; Sun, 07 Feb 2021 22:55:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35634) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l8x6H-0007iD-Qa for qemu-devel@nongnu.org; Sun, 07 Feb 2021 22:20:33 -0500 Received: from mail-il1-x12b.google.com ([2607:f8b0:4864:20::12b]:35398) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l8x6D-0001is-Gp for qemu-devel@nongnu.org; Sun, 07 Feb 2021 22:20:33 -0500 Received: by mail-il1-x12b.google.com with SMTP id o7so6946234ils.2 for ; Sun, 07 Feb 2021 19:20:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=o0Vd6bwYd4gneYtpxWheq/+EF/MLp77aqunUp/r0WeM=; b=WJPJFFmCjI7Cy+8Li3azAORG2h7v0NTSoYCGKPU0wxeofQMYxpx+oM+NkkFfA6t9H1 sTcxABNPNNcNgOqIUIRIO4yH3MsbYh42UCft2AG13RQAC3n3MlvLGbqYAJzDEJWQFfGp 6eppHMUpKu9KkA9ywJw+WltsQd1qLNRrpTchv1U3NkhIDJWJEPUyM+WzI0Fv4UwffVMt +0hyZCn6iJtzxaR/R1EAwFBA+UJWfyeSW+H0b+i7ZUYxG8wSdbbs/Pag0kRIR23wOHbK b+OU8mEl2PoV2nQE0l4v1GR88mqAUFBjVAyqbPyjszq8dlpGCYwt1uKTGQPaI9gKgxh2 5zGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=o0Vd6bwYd4gneYtpxWheq/+EF/MLp77aqunUp/r0WeM=; b=KD2Wkh6cPLNyDOyEVNvd9fApU42o79hw+K3AOHtRJvQGXf6Qqal5x4KSahehU+XAUt XHBgHR3dYnwNqDOZZpVBGYCGmZKaNzMHfYiWO4Xo5kRkFu2y5YJFnJpVXosrB319k41M UQ9PVdCqQTW56KpQOD4IQMYkjrr4qgj9AfcnUKaVh5z1LEUG5uh1awiGJTKZZacBLppb ycezV4PRcKy5pX8fVwYWMluMSnH3rBT/Yytu8bjdy5iKJLKICQwhzkPmNj4gvEfiq/Xm aYzioqlVSIN2EhXV5dMBKZbh0V3znGKmC15mEYZCEfP6T2W2CBlA6EF60XoSZlFNA1R/ N6Vg== X-Gm-Message-State: AOAM533aO6KfQokvO4eocn2MwWtnQR0xTNxKumVMURVRlqjG5w4wq7U4 dqArLcTfLjnTDGxZnmP8u9zc X-Received: by 2002:a92:d485:: with SMTP id p5mr12873827ilg.114.1612754428532; Sun, 07 Feb 2021 19:20:28 -0800 (PST) Received: from localhost.localdomain ([147.75.106.138]) by smtp.gmail.com with ESMTPSA id o8sm8022965ilu.55.2021.02.07.19.20.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Feb 2021 19:20:28 -0800 (PST) From: Haibo Xu To: drjones@redhat.com, richard.henderson@linaro.org Subject: [RFC PATCH 3/5] Add APIs to get/set MTE tags Date: Mon, 8 Feb 2021 03:20:04 +0000 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::12b; envelope-from=haibo.xu@linaro.org; helo=mail-il1-x12b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, qemu-arm@nongnu.org, philmd@redhat.com, qemu-devel@nongnu.org, Haibo Xu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" MTE spec provide instructions to retrieve the memory tags: (1) LDG, at 16 bytes granularity, and available in both user and kernel space; (2) LDGM, at 256 bytes granularity in maximum, and only available in kernel space To improve the performance, KVM has exposed the LDGM capability to user space by providing a new APIs. This patch is just a wrapper for the KVM APIs. Signed-off-by: Haibo Xu --- target/arm/kvm64.c | 24 ++++++++++++++++++++++++ target/arm/kvm_arm.h | 2 ++ 2 files changed, 26 insertions(+) -- 2.17.1 diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c index 23f34034db..4a6790d53b 100644 --- a/target/arm/kvm64.c +++ b/target/arm/kvm64.c @@ -1608,3 +1608,27 @@ bool kvm_arm_verify_ext_dabt_pending(CPUState *cs) } return false; } + +int kvm_arm_mte_get_tags(uint64_t ipa, uint64_t len, uint8_t *buf) +{ + struct kvm_arm_copy_mte_tags args = { + .guest_ipa = ipa, + .length = len, + .addr = buf, + .flags = KVM_ARM_TAGS_FROM_GUEST, + }; + + return kvm_vm_ioctl(kvm_state, KVM_ARM_MTE_COPY_TAGS, &args); +} + +int kvm_arm_mte_set_tags(uint64_t ipa, uint64_t len, uint8_t *buf) +{ + struct kvm_arm_copy_mte_tags args = { + .guest_ipa = ipa, + .length = len, + .addr = buf, + .flags = KVM_ARM_TAGS_TO_GUEST, + }; + + return kvm_vm_ioctl(kvm_state, KVM_ARM_MTE_COPY_TAGS, &args); +} diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h index eb81b7059e..1b94dbe7c8 100644 --- a/target/arm/kvm_arm.h +++ b/target/arm/kvm_arm.h @@ -358,6 +358,8 @@ int kvm_arm_vgic_probe(void); void kvm_arm_pmu_set_irq(CPUState *cs, int irq); void kvm_arm_pmu_init(CPUState *cs); +int kvm_arm_mte_get_tags(uint64_t ipa, uint64_t len, uint8_t *buf); +int kvm_arm_mte_set_tags(uint64_t ipa, uint64_t len, uint8_t *buf); /** * kvm_arm_pvtime_init: From patchwork Mon Feb 8 03:20:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haibo Xu X-Patchwork-Id: 378509 Delivered-To: patch@linaro.org Received: by 2002:a02:b18a:0:0:0:0:0 with SMTP id t10csp4339708jah; Sun, 7 Feb 2021 19:44:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJxbfT81mOBU3g4ulvn9lIh3nYRiNy/ib1gGLte3XFvaLbriS9084M3E5x3qvtz3m5qRAkbg X-Received: by 2002:a25:bbd0:: with SMTP id c16mr22954629ybk.23.1612755876264; Sun, 07 Feb 2021 19:44:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612755876; cv=none; d=google.com; s=arc-20160816; b=rXFfrciEf77/plF6pWRFEMfinbBdriEMwT0wEceafSiWdrH+teucyGonbZlaL/goNL OTRh4bNVUwOj+Y1IhajQ2HXYjb5dTWTbV2Hh2bHG9a/thh1DZCKmHuTVuFa2vx9Tyfy0 IjxcDhUgRKTOrB4zk2OtdUxmVNdI5laROXo/KvOkCmKTM8S4Cs1We+ogycBn4a+5EtwB pdmGqfHMNxk2GQCHFRax0HEHKQIYtsJt6w9kvm1YDWbu/sijdmrFtMawDvRfZvQePE+6 flFRp0/h5Yuzum3WTqEbQ/H/hw70WkIBeBDb1Qr86c9LmgwDCRL7gh+kH4UmDyC9fJyX zLTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=E8zwyqjjxJulzipec2YkM3SoTdlEFmhkzHgrzxKzdEs=; b=GJOrwu6v67/S3MkjMdZAa8aDVc4jux7WMcMrwt3sgGaTFQaPvYPTLRuojdUp6WoCIj XhAHt5fkKPQcj8ItAqBtk7Wu2VGte08HfEi4YNMiXdBHI8PDusYnqIZ3jSxmIQrGEveq UPKjlN4C/yHpvxRr9RuiOKi0e+qOSQZdIKrcJrfPj1/+UZSrF1OWEvnVwspBzeRO/GZk KSdi4Jw0HXcTDUPTVqOm7yDSKxQrC4WJaPT0DGX5AltFivPH3z9Gp2gnyPMSP7+jMhkh +4cnWz6ZgqpwtOi033jjHav1urzWaHsdy5UWU0wOOEmzaMjqhGs0e0wDGH4b4vNequzz c7cA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=SkGZIlbM; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id q189si2962069ybb.188.2021.02.07.19.44.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 07 Feb 2021 19:44:36 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=SkGZIlbM; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:43908 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l8xTX-0004kH-EO for patch@linaro.org; Sun, 07 Feb 2021 22:44:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35654) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l8x6I-0007jw-KH for qemu-devel@nongnu.org; Sun, 07 Feb 2021 22:20:34 -0500 Received: from mail-il1-x131.google.com ([2607:f8b0:4864:20::131]:39894) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l8x6E-0001jm-De for qemu-devel@nongnu.org; Sun, 07 Feb 2021 22:20:34 -0500 Received: by mail-il1-x131.google.com with SMTP id d6so11465893ilo.6 for ; Sun, 07 Feb 2021 19:20:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=E8zwyqjjxJulzipec2YkM3SoTdlEFmhkzHgrzxKzdEs=; b=SkGZIlbMN8tKuqjTMYzRNgWDk5au8iErybhksXcW6HIw435lJC6WGXh61mnsqHcHnk t/D99BOROAHQmP8qKk6myuXP87CHJ8uLsZYXTuns/ylEB3c0g/lAvRmxy237V7zcnRAf 3py60I1t68fFs7wsuV74s284hLUHOe5ZSw8YJ88BkZZlpPGO2H/Wbx86spEvQanXxVAy dMDAnx9QiwmU2tU2pN1pwOLHNsrfvhwek8sD20W3XvuJIqFQtDoeBQQzz/WnH4JJ9nY2 LUQ45WBcbbqyu+0iBBFjcpz/VKoJDsCCvqVGyvxNlGSwZSSTozNcyX38srOhcutquj7Y jNHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=E8zwyqjjxJulzipec2YkM3SoTdlEFmhkzHgrzxKzdEs=; b=k1h+D7tH82R0PtBZ+lId43Oc59vJH9mbfBwcEmyFBfK/0aaHy2KH0spy5HJjyfMFCR EvXy0agU6R06BPz34n3HYeC4p+xNnSUUOcGt1kYzoBMNlCgAiIMzadkO96rcVGLQAcye Pw8YGR4897NHq7DCYwSebDjk6O6c9qsh+a+WQh4oA7vXDsoskLT+2eJKuKTmbybmvf// EwxSl/jxja/X/uCnNKfNZqyl9cvW+dHg2NskN+M4TfCO/XNMxNtTppAQrSJmZDF/XCOi ZXneuRme2wLxhjweOlchm2s4nzSyxWdj3wYdmNxcWWonAA1iBrWF/AaaB13VHQem1Swo BxVQ== X-Gm-Message-State: AOAM53054Pi4JR/da+jy1gH5JZJrxOOkYszwZhomnUonTPRo/w5kZpYp VmtTtuJrSJKIAzCRnta3UauDdaerOnPSHrQ= X-Received: by 2002:a05:6e02:1608:: with SMTP id t8mr13992323ilu.79.1612754429418; Sun, 07 Feb 2021 19:20:29 -0800 (PST) Received: from localhost.localdomain ([147.75.106.138]) by smtp.gmail.com with ESMTPSA id o8sm8022965ilu.55.2021.02.07.19.20.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Feb 2021 19:20:29 -0800 (PST) From: Haibo Xu To: drjones@redhat.com, richard.henderson@linaro.org Subject: [RFC PATCH 4/5] Add migration support for KVM guest with MTE Date: Mon, 8 Feb 2021 03:20:05 +0000 Message-Id: <25a922038d256e47f3eb99683c5e3bd9c34753ac.1612747873.git.haibo.xu@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::131; envelope-from=haibo.xu@linaro.org; helo=mail-il1-x131.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, qemu-arm@nongnu.org, philmd@redhat.com, qemu-devel@nongnu.org, Haibo Xu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" To make it easier to keep the page tags sync with the page data, tags for one page are appended to the data during ram save iteration. This patch only add the pre-copy migration support. Post-copy and compress as well as zero page saving are not supported yet. Signed-off-by: Haibo Xu --- include/hw/arm/virt.h | 2 + include/migration/misc.h | 1 + migration/ram.c | 86 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 88 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h index 36fcb29641..6182b3e1d1 100644 --- a/include/hw/arm/virt.h +++ b/include/hw/arm/virt.h @@ -165,6 +165,8 @@ struct VirtMachineState { DeviceState *acpi_dev; Notifier powerdown_notifier; PCIBus *bus; + /* migrate memory tags */ + NotifierWithReturn precopy_notifier; }; #define VIRT_ECAM_ID(high) (high ? VIRT_HIGH_PCIE_ECAM : VIRT_PCIE_ECAM) diff --git a/include/migration/misc.h b/include/migration/misc.h index bccc1b6b44..005133f471 100644 --- a/include/migration/misc.h +++ b/include/migration/misc.h @@ -38,6 +38,7 @@ void precopy_add_notifier(NotifierWithReturn *n); void precopy_remove_notifier(NotifierWithReturn *n); int precopy_notify(PrecopyNotifyReason reason, Error **errp); void precopy_enable_free_page_optimization(void); +void precopy_enable_metadata_migration(void); void ram_mig_init(void); void qemu_guest_free_page_hint(void *addr, size_t len); diff --git a/migration/ram.c b/migration/ram.c index 7811cde643..32f764680d 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -53,9 +53,11 @@ #include "block.h" #include "sysemu/sysemu.h" #include "sysemu/cpu-throttle.h" +#include "sysemu/kvm.h" #include "savevm.h" #include "qemu/iov.h" #include "multifd.h" +#include "kvm_arm.h" /***********************************************************/ /* ram save/restore */ @@ -75,6 +77,9 @@ #define RAM_SAVE_FLAG_XBZRLE 0x40 /* 0x80 is reserved in migration.h start with 0x100 next */ #define RAM_SAVE_FLAG_COMPRESS_PAGE 0x100 +#define RAM_SAVE_FLAG_MTE 0x200 + +#define MTE_GRANULE_SIZE (16) static inline bool is_zero_range(uint8_t *p, uint64_t size) { @@ -310,6 +315,8 @@ struct RAMState { bool ram_bulk_stage; /* The free page optimization is enabled */ bool fpo_enabled; + /* The RAM meta data(e.t memory tag) is enabled */ + bool metadata_enabled; /* How many times we have dirty too many pages */ int dirty_rate_high_cnt; /* these variables are used for bitmap sync */ @@ -387,6 +394,15 @@ void precopy_enable_free_page_optimization(void) ram_state->fpo_enabled = true; } +void precopy_enable_metadata_migration(void) +{ + if (!ram_state) { + return; + } + + ram_state->metadata_enabled = true; +} + uint64_t ram_bytes_remaining(void) { return ram_state ? (ram_state->migration_dirty_pages * TARGET_PAGE_SIZE) : @@ -1127,6 +1143,61 @@ static bool control_save_page(RAMState *rs, RAMBlock *block, ram_addr_t offset, return true; } +static int save_normal_page_mte_tags(QEMUFile *f, uint8_t *addr) +{ + uint8_t *tag_buf = NULL; + uint64_t ipa; + int size = TARGET_PAGE_SIZE / MTE_GRANULE_SIZE; + + if (kvm_physical_memory_addr_from_host(kvm_state, addr, &ipa)) { + /* Buffer for the page tags(one byte per tag) */ + tag_buf = g_try_malloc0(size); + if (!tag_buf) { + error_report("%s: Error allocating MTE tag_buf", __func__); + return 0; + } + + if (kvm_arm_mte_get_tags(ipa, TARGET_PAGE_SIZE, tag_buf) < 0) { + error_report("%s: Can't get MTE tags from guest", __func__); + g_free(tag_buf); + return 0; + } + + qemu_put_buffer(f, tag_buf, size); + + g_free(tag_buf); + + return size; + } + + return 0; +} + +static void load_normal_page_mte_tags(QEMUFile *f, uint8_t *addr) +{ + uint8_t *tag_buf = NULL; + uint64_t ipa; + int size = TARGET_PAGE_SIZE / MTE_GRANULE_SIZE; + + if (kvm_physical_memory_addr_from_host(kvm_state, addr, &ipa)) { + /* Buffer for the page tags(one byte per tag) */ + tag_buf = g_try_malloc0(size); + if (!tag_buf) { + error_report("%s: Error allocating MTE tag_buf", __func__); + return; + } + + qemu_get_buffer(f, tag_buf, size); + if (kvm_arm_mte_set_tags(ipa, TARGET_PAGE_SIZE, tag_buf) < 0) { + error_report("%s: Can't set MTE tags to guest", __func__); + } + + g_free(tag_buf); + } + + return; +} + /* * directly send the page to the stream * @@ -1141,6 +1212,10 @@ static bool control_save_page(RAMState *rs, RAMBlock *block, ram_addr_t offset, static int save_normal_page(RAMState *rs, RAMBlock *block, ram_addr_t offset, uint8_t *buf, bool async) { + if (rs->metadata_enabled) { + offset |= RAM_SAVE_FLAG_MTE; + } + ram_counters.transferred += save_page_header(rs, rs->f, block, offset | RAM_SAVE_FLAG_PAGE); if (async) { @@ -1152,6 +1227,11 @@ static int save_normal_page(RAMState *rs, RAMBlock *block, ram_addr_t offset, } ram_counters.transferred += TARGET_PAGE_SIZE; ram_counters.normal++; + + if (rs->metadata_enabled) { + ram_counters.transferred += save_normal_page_mte_tags(rs->f, buf); + } + return 1; } @@ -1905,6 +1985,7 @@ static void ram_state_reset(RAMState *rs) rs->last_version = ram_list.version; rs->ram_bulk_stage = true; rs->fpo_enabled = false; + rs->metadata_enabled = false; } #define MAX_WAIT 50 /* ms, half buffered_file limit */ @@ -3492,7 +3573,7 @@ static int ram_load_precopy(QEMUFile *f) trace_ram_load_loop(block->idstr, (uint64_t)addr, flags, host); } - switch (flags & ~RAM_SAVE_FLAG_CONTINUE) { + switch (flags & ~(RAM_SAVE_FLAG_CONTINUE | RAM_SAVE_FLAG_MTE)) { case RAM_SAVE_FLAG_MEM_SIZE: /* Synchronize RAM block list */ total_ram_bytes = addr; @@ -3562,6 +3643,9 @@ static int ram_load_precopy(QEMUFile *f) case RAM_SAVE_FLAG_PAGE: qemu_get_buffer(f, host, TARGET_PAGE_SIZE); + if (flags & RAM_SAVE_FLAG_MTE) { + load_normal_page_mte_tags(f, host); + } break; case RAM_SAVE_FLAG_COMPRESS_PAGE: From patchwork Mon Feb 8 03:20:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haibo Xu X-Patchwork-Id: 378532 Delivered-To: patch@linaro.org Received: by 2002:a02:b18a:0:0:0:0:0 with SMTP id t10csp4357849jah; Sun, 7 Feb 2021 20:21:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJwB3FWJhWC8gqUVyurghyyWgD4tfsRVd6y1mJAamcucBn6n7trDGmWve/Dv0mttkj/QjoUD X-Received: by 2002:a25:c244:: with SMTP id s65mr23561517ybf.128.1612758080189; Sun, 07 Feb 2021 20:21:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612758080; cv=none; d=google.com; s=arc-20160816; b=KKCoL2Y4lNRFKCsNz9z/brhmNcK/E2NdXE2UqVXgLN/Vd1ht7q34CIiTd5I43PWvVr +mHGVedQeSXnknf0ff5TrDqL8VgX4FGQ4CX/EbYMqoTWeJ3Pu3gBs/REDJvLY/jZ/K1Q 8DVzlg3VdTYeYzKRUex8BCmOuGhESBdEeTmAHo8rI9uz3e9IvNOeGPCjyn8uf18Vib1u yf0s/CpZaYE9tIWlzt0jSp6VuOHh6c3Pj6cd3/jKni+G6j15GuPwykO/P/pXH6m6MicS RS2sDvro6bBQVXoBA0CJN1tvUyVPMrq7go9hy5Ry/H/g8Os/oMWWWMuCC7wk7EhrJb69 1bmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=Wfrxe2AEinW34K0GuFsTKfhMgJ70NeWcmQ/m1I/W4tU=; b=Ovk+H8vJfcavojK0FpmVpxNJABE3AEfSIVf8pUw0Vq2tB9dAtXVxxwynu+f6HlujAT JuGSadFUoOC5bE/hGPRLFIVG41yrAyMVxM45Bp2KMg8FF+JJiPWea77Tg8G989+R9oNy wVFDv6gYRaaYW/teiB44PP5a4aeXmHTcHIJ6SseFYsqSjB3KbTklllS+vQG2WCkpZOI7 WgYdLIvufJIeIL3D0BoCPxAbZ7drU0rxoqIRHWiyekT+dU7WwYm8+16tSzgpAXfEi940 cqhEQw9tYy1ONdrEll8M3M8bTbqfNV0sC+9c5va8YEq/AL43fg931SerndqvqMaKCAJq 2Q0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=MGOteG1t; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g32si1979945ybj.490.2021.02.07.20.21.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 07 Feb 2021 20:21:20 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=MGOteG1t; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:34316 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l8y35-0004FX-Ld for patch@linaro.org; Sun, 07 Feb 2021 23:21:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35664) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l8x6J-0007l8-Bx for qemu-devel@nongnu.org; Sun, 07 Feb 2021 22:20:35 -0500 Received: from mail-il1-x134.google.com ([2607:f8b0:4864:20::134]:34669) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l8x6G-0001k2-5S for qemu-devel@nongnu.org; Sun, 07 Feb 2021 22:20:35 -0500 Received: by mail-il1-x134.google.com with SMTP id q9so11496723ilo.1 for ; Sun, 07 Feb 2021 19:20:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Wfrxe2AEinW34K0GuFsTKfhMgJ70NeWcmQ/m1I/W4tU=; b=MGOteG1tAXL7clmx6mozj3kJm8zN1mKOSl5adIZe31SqVf5ZePTq0s33hjMzU/e/Ar rUcGCuHuHTAhLi6iKxJ95AkX9jQBcn/7Bd4pfuyTq2oxisbMtm0FJJbz4yCshAlFuKja br1sGPCmsGZ85cjxUrTpFddoKDdd2pQKVdEwCawU4RZintNzMJhMIaQZQMwEzKxEKMXg HXMUu9Sj0qRzitTZ//7L6A6h+5RJmnO/gzDxfPUYcfAAyagDQ0/2vQ/NZTnzbLtogeEW MmeKuFtOlpfGZ4nKLVyrFo6QaiKFjv7EiH33KkD8CK4V97M7JkHpo3ojBhJBMRqVM64+ 1kUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Wfrxe2AEinW34K0GuFsTKfhMgJ70NeWcmQ/m1I/W4tU=; b=kapX0KdLdVtbGE4UR/escOXeVH6Sv8Hlh3mewgza+e5DO7jKQKRto2iEbBLCO4iQde acxfEKu5ZmBBGU3TkqDg4HTF1sX1SyiSuDsvlgg78sopajGs4VKOBjmQsiC94M8Tw19/ cEMhta5f1XSu/nrs8R99G4/HEOzurJuhEZMIn0ufs6sLXvAgZHb3hbuFUm26noSdQa0e wVGx4s2Bmi+f35W1rAu8demvNxNehhNGslvhvAcQGXy8blaHBsUGedNBZNefti/zHCYM QBC12WYoBc+voDjpbOU7wTYM9mvsRDB9sMaeL4o+wWJAIs5do0yPqdBgZMjGpUQR2z6E bx8Q== X-Gm-Message-State: AOAM532p4eeK5VTMbZfzWIXVSt6Fq/0g2tYxZwKJaHw48GWvdMbpCojB XQ5vYG9H8wSaJiNYIc7Y9ccV X-Received: by 2002:a05:6e02:e51:: with SMTP id l17mr12795315ilk.199.1612754430274; Sun, 07 Feb 2021 19:20:30 -0800 (PST) Received: from localhost.localdomain ([147.75.106.138]) by smtp.gmail.com with ESMTPSA id o8sm8022965ilu.55.2021.02.07.19.20.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Feb 2021 19:20:29 -0800 (PST) From: Haibo Xu To: drjones@redhat.com, richard.henderson@linaro.org Subject: [RFC PATCH 5/5] Enable the MTE support for KVM guest Date: Mon, 8 Feb 2021 03:20:06 +0000 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::134; envelope-from=haibo.xu@linaro.org; helo=mail-il1-x134.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, qemu-arm@nongnu.org, philmd@redhat.com, qemu-devel@nongnu.org, Haibo Xu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Haibo Xu --- hw/arm/virt.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) -- 2.17.1 diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 623d5e9397..c2358cf4c5 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -79,6 +79,7 @@ #include "hw/virtio/virtio-iommu.h" #include "hw/char/pl011.h" #include "qemu/guest-random.h" +#include "migration/misc.h" #define DEFINE_VIRT_MACHINE_LATEST(major, minor, latest) \ static void virt_##major##_##minor##_class_init(ObjectClass *oc, \ @@ -821,6 +822,21 @@ static void virt_powerdown_req(Notifier *n, void *opaque) } } +static int virt_precopy_notify(NotifierWithReturn *n, void *data) +{ + PrecopyNotifyData *pnd = data; + + switch (pnd->reason) { + case PRECOPY_NOTIFY_SETUP: + precopy_enable_metadata_migration(); + break; + default: + break; + } + + return 0; +} + static void create_gpio_keys(const VirtMachineState *vms, DeviceState *pl061_dev, uint32_t phandle) @@ -1898,9 +1914,9 @@ static void machvirt_init(MachineState *machine) } if (vms->mte && kvm_enabled()) { - error_report("mach-virt: KVM does not support providing " - "MTE to the guest CPU"); - exit(1); + /* connect migration precopy request */ + vms->precopy_notifier.notify = virt_precopy_notify; + precopy_add_notifier(&vms->precopy_notifier); } create_fdt(vms);