From patchwork Wed Mar 17 09:28:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haibo Xu X-Patchwork-Id: 403109 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp304181jai; Wed, 17 Mar 2021 02:29:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyuDvZlyo1HR/La1+dzAPWWerW+hpy9Fw9A13gLm2qpaHWCtf4PSEAo029XDItFEjZt+IjC X-Received: by 2002:a25:2e41:: with SMTP id b1mr2093786ybn.15.1615973379855; Wed, 17 Mar 2021 02:29:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615973379; cv=none; d=google.com; s=arc-20160816; b=Vkn6csTe8jhb7UlizKZrApJ8Y+NVGJiu6UhJ7ePTkZwOj1Pc94RKlBfTDrf2QAznGe f3YrxZce9fwQdR+ErdKntNF3vOH+o7lLZ0+fDCp5IE5PdtBzqyZ/me6Bu9Nt70JOTjwF SL6wfSES25tE0srneTI/BuMJwd7QdKIKv6ihjJkxIpvr1Gmq1hmzGY6XvXbgTAcPX4B2 lsgXJfjKf54T0dicY9WH/kLF/duD+oxqpXj0OOJbhX6aAIoNFU66Nz4+yvR6AsBP2VpB UOl+CmcQYjC+MDRYPrrLrygSDHZnM8oSAkWGKvIp59HULQ4AA6u8I33NSsNSDdabKqGx WImg== 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=Q+3SQ1h/ZiK+NQG+zSbCG676wEEMohnKSXfyBletwdI=; b=xLwaMJB/dG7XRPQCBByTuulbsT6uJQmH8/vGN9sH8Th8CVHqzMCs2EXyq6NAEpTvBA KPTE83nFb8OtsTuIAnwONYBXJWuFSEALXqBOS1KHU3rSCgSeBsLEe8n2wybeh2JpUQ+c ndu5brNLX5tkpiEmsR84Q142LEr4ddwLppp6J5XRf/4WOB4vt7QKj99oyRg/7lN1zjUQ 0ZznT5XDS+zCHM/ku2svxcgxLxO3Qlaq8bSzEuKwvubOZpoGPI/OKitrOsyqROcsp3/q TwF82u2ldvhP1uVSjSA2y+IhU3wYTmyWJMuKIQHDi0qAu5WLpktAmsHX18FkYsJko4aj ucew== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Mo3EXAXS; 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 l206si26791401ybc.64.2021.03.17.02.29.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 17 Mar 2021 02:29:39 -0700 (PDT) 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=Mo3EXAXS; 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]:45540 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lMSUl-0002JM-Bv for patch@linaro.org; Wed, 17 Mar 2021 05:29:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46596) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMSTw-0001lg-Eq for qemu-devel@nongnu.org; Wed, 17 Mar 2021 05:28:48 -0400 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]:37203) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lMSTu-00013d-4u for qemu-devel@nongnu.org; Wed, 17 Mar 2021 05:28:47 -0400 Received: by mail-pg1-x52c.google.com with SMTP id o10so24439486pgg.4 for ; Wed, 17 Mar 2021 02:28:45 -0700 (PDT) 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=Q+3SQ1h/ZiK+NQG+zSbCG676wEEMohnKSXfyBletwdI=; b=Mo3EXAXS9ISjyYdntIfJ2GRk1WZJZkm0kOxi4kC0l2UQz6SCoxLUHssI5zKspwxoss OWP9VHNroyIMuZrCYIlIAoS9wvmEBskBf2xW7vzn7QMVfUU4ZmbZb4YbEG3YseFjp+tf CfB2ZiqHOdNGj9Dv+3/NI9ibLoBxfBi3ywlQNo+2V4iGpI/VEnZg9GfHsghhKhTViWDU kb4G6BSyhywEttloJN5L3R4bmfkmwMy7GD8uZ0QnGjk95lytohdRBA1rC25OHV9XpFTs E+0bDW9M+85TFG0sDr5Dag1pbQyZewgnXPHgrNe+9GlKNL42NLcgbrK/dL4Tu2x0ySNW AZPw== 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=Q+3SQ1h/ZiK+NQG+zSbCG676wEEMohnKSXfyBletwdI=; b=iz5e/RPOqYW5sCLwyEy1v/3C7pvAgiYxSu/tzoccRoF/uOWAIv2416JZU5/S7Pn/Mi 512q/KtMuXij2QEzo2AUvmweOl693gZSm8+3zq3QWL0gydHV5a5jN4bXECKU1clQUeM1 PpUhXOhG0jdl6NZYf0yWDj8y+EiuMnyF973yFwOL7SUnc2im52nAEDY4EOYIF94RECg/ PATLFuj9gaTxd9TnOadjnmniqp54LdMOWRO0EuOF29AwjbNYR+shA3QfdaUnRemPpbHr V/jJtA55oQia3u5GC5yI56gbI9ogDJ6hSoIUjGK1C57nFDuv/eQGjVJNg/0FAZD1Og31 PrvQ== X-Gm-Message-State: AOAM5312STF/qzMIMH5rABclfsZQdA9PCNN8xmJWsWxQFMNgf+uGp09C Wvr+l4l9XyI8XwmA09N0TTT9 X-Received: by 2002:a62:e90c:0:b029:203:90f:6f34 with SMTP id j12-20020a62e90c0000b0290203090f6f34mr3401533pfh.29.1615973324687; Wed, 17 Mar 2021 02:28:44 -0700 (PDT) Received: from localhost.localdomain ([147.75.106.138]) by smtp.gmail.com with ESMTPSA id r30sm18630163pgu.86.2021.03.17.02.28.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 02:28:40 -0700 (PDT) From: Haibo Xu To: dgilbert@redhat.com, quintela@redhat.com, drjones@redhat.com, richard.henderson@linaro.org Subject: [RFC PATCH v2 1/5] Update Linux headers with new MTE support Date: Wed, 17 Mar 2021 09:28:20 +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::52c; envelope-from=haibo.xu@linaro.org; helo=mail-pg1-x52c.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" Signed-off-by: Haibo Xu --- linux-headers/linux/kvm.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) -- 2.17.1 diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h index 020b62a619..941743b3a7 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 195 #ifdef KVM_CAP_IRQ_ROUTING @@ -1241,6 +1242,20 @@ 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; + __u64 reserved[2]; +}; + /* * Device control API, available with KVM_CAP_DEVICE_CTRL */ @@ -1396,6 +1411,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 Wed Mar 17 09:28:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haibo Xu X-Patchwork-Id: 403111 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp306103jai; Wed, 17 Mar 2021 02:32:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCUvsfe8DS57jXt4wRZqKIuMxE7usDPPy5aC7DMUQyfW3l5sexnOE/lW7TXC8t95ZNE1Ev X-Received: by 2002:a5b:f0d:: with SMTP id x13mr3359440ybr.520.1615973566834; Wed, 17 Mar 2021 02:32:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615973566; cv=none; d=google.com; s=arc-20160816; b=LeTXkcNQwrlbPF9hNVCK50XJzYQGJe25emSIAAgOVFB9H0/I3XNvJYODEDRmFztJUQ mLBV482XK4JenybgVs2Apopei5cHzTp8pWuwK+G3Dd3ijBybmIh8F8Pet3JVGk1YQvmg /K+InLn+jgruQJPfnZ5gIeOrHXXpz2sf9ZYCiDXZsU0pm8Df/VBlFSfkEpxUDeXrOEJ6 m/5AFgd2I96qkAJgG3STaxHHey9BDkV2meMbRfkAYChsnwcGio1rpA4pKgGDnDTEgVCQ 6ipZdJv7twquDvKWwsblFLhRjM10JJCfQSTBVSg6v6fE56u0Kt8q9an3f1T/E/G7prwV Tz1A== 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=69KRFSXYjzFlJT+Yhq6KsYSkZCWp63z+0u1KJALVHNA=; b=LWDHSjgkCRQRHehxep9VvTK7aA6vfkVe1Qlw5edrfpX76jZt4SHTnnchOLcKS7m66z Kr8PzyB6yiMgjTJNRUnutnK5xV5GYKQq3RUiMjzd4wOsyivs9vuk1G117T1Pjo6OdDSw hVgyWfHKqtP1dzsiBn1AHGXdVOmZ29PvAGLSHEiMSPEaXflE8g1ZFbRJhLHcm56AVHXT NqjYdMOHxbY72pzKQoXGU67NLi+d9QTIkzEuz7XLwvxUrfSjWoi3R70DeQNBz85LWpSS 1QTxs+Xp4D+PIbRwL+WJ4ifCW9ZLzO+0501OMPvXQhakTbeK8dXSgQVS2Kectt4r0z8Y DLCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=K6Z9UjHE; 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 w3si19855259ybs.173.2021.03.17.02.32.46 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 17 Mar 2021 02:32:46 -0700 (PDT) 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=K6Z9UjHE; 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]:50992 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lMSXm-0004et-85 for patch@linaro.org; Wed, 17 Mar 2021 05:32:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46618) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMSTy-0001nv-EP for qemu-devel@nongnu.org; Wed, 17 Mar 2021 05:28:51 -0400 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]:51880) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lMSTv-00014R-UW for qemu-devel@nongnu.org; Wed, 17 Mar 2021 05:28:50 -0400 Received: by mail-pj1-x102c.google.com with SMTP id s21so781519pjq.1 for ; Wed, 17 Mar 2021 02:28:47 -0700 (PDT) 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=69KRFSXYjzFlJT+Yhq6KsYSkZCWp63z+0u1KJALVHNA=; b=K6Z9UjHEZYHee0gFfJmGGCucD9CZzFrEKcarXyT4TXAo+E3rSf0FAOW8Iavko+tTSh kCGYxou/IKR+nL4CHNnPkzELpxp3K5DAfZTpgP3muHYxOXIZo0sBdQWUa2e4tuL3+MZd zHbsER/bGfrgYU1IeemiJPueLSeUKvhXdgqKf622ucyILlYNXvHV7X0hOtX3sr82EKD4 65D0ALDt7cA3IgQDEKCwKmMa5SmQC0u7HWMMBGB5pXD5kdJlKm3AO8EKvVu++xJYLFzK jZesvDwvf8+YTTGLd4btO6qHTenIcDs/tXUSLKb7Vx55+9atgSt35W7BbrMi8bPmmfAr RAag== 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=69KRFSXYjzFlJT+Yhq6KsYSkZCWp63z+0u1KJALVHNA=; b=k0+4cYTKrxcBVxfJ57M0TeMZ8F33cUfLGB7oB+2KNb6POSQNMz0KahDCZsv3EzRjsy DcuTanwyP2YqccOj9hU7T8AKC5meWCqDektxKvfFDWK7/4ixSpbUsd+Rf1YxKoJh7sAt GWVz8pefZy3OsGqOdgCuJCOGnnd01M4LAzowAqGtnT5ljk/n6Dn5zx7G+Th5LfgTTmP6 3Z+vgpoTbPEKQX61ulHw7FtSs1jO1tm07u2Q6Iu0CgagXWhpiyd1yj+sF697HGeFWuGB w+GK3P4XN4LJaVY+qwfer2lmW2wsmUl4/jGiDwS9qgKitt+QQg6BQuKF+Ha2VzDR6XWD APCA== X-Gm-Message-State: AOAM5337xy+qfrMomSHnWpDp1MamDPVCLF+De/WtRJ+RcaNDHXOP7z05 eEL9k7nbt5ya3mOeWAI4ee9Y X-Received: by 2002:a17:902:f1c2:b029:e4:6c23:489f with SMTP id e2-20020a170902f1c2b02900e46c23489fmr3813518plc.62.1615973326296; Wed, 17 Mar 2021 02:28:46 -0700 (PDT) Received: from localhost.localdomain ([147.75.106.138]) by smtp.gmail.com with ESMTPSA id r30sm18630163pgu.86.2021.03.17.02.28.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 02:28:46 -0700 (PDT) From: Haibo Xu To: dgilbert@redhat.com, quintela@redhat.com, drjones@redhat.com, richard.henderson@linaro.org Subject: [RFC PATCH v2 2/5] Add basic MTE support to KVM guest Date: Wed, 17 Mar 2021 09:28:21 +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::102c; envelope-from=haibo.xu@linaro.org; helo=mail-pj1-x102c.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 aa2bbd14e0..76658b93a3 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -1988,18 +1988,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 ae04884408..47bf817b61 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -1847,7 +1847,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 d8381ba224..3403e621ac 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 @@ -274,6 +275,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 dff85f6db9..73a191f8e1 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 Wed Mar 17 09:28:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haibo Xu X-Patchwork-Id: 403114 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp307887jai; Wed, 17 Mar 2021 02:35:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/8xrjEQJ4jOs65RHNphdXCxH72GE0Bx5iYtAl++VIMd+iD9HKCfqqelM+AEkRXRm1So+P X-Received: by 2002:a25:ad67:: with SMTP id l39mr3446502ybe.172.1615973743181; Wed, 17 Mar 2021 02:35:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615973743; cv=none; d=google.com; s=arc-20160816; b=t8m6JUNXNlrx4i5tL5Tfs3Ui9FGBYJOIH7cjKfozbX1ElUYZOSiT6qlhsCoKyQnsHn 38lPVN52hpBoVRifr9MkPB5//lQUeyZmPgncPzv2QNYdnCGKrcs/H+hLuwfYV2Os0HrT C6fT1l2F+yVQCBfotDropbgWQDVwtkFLlXuidEAOQZe80zmdv/iqQ3CEryy6ItYtqbNe TLlY7VC0WXCb9uu2ea5b3WtYPUCRME2ed8SuoLuyxbC4w6b0UARXf8AT126gxthvDWX/ +TVjyxLsGFi01PPdxDtAwcEWKDoWHr/k55V74+7NYGT0F/Y0v3lJvS0WwK5gjn3qjzRx CXcQ== 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=kaO/3XjDddPfI9XqP7E0JoVJAI1xFWhKSBbTYqDo4uw=; b=AZC2rVbD9bdp+X5VK+2V6rHnDiTuSsjDy+dLTx/sQI0pUYaXujzofm0pxF7FNYh7jX y/esyIUG2tpahvWQkt+xI9tJ52QQ3Q+gURGamW6yXJrsgd+znWbeUbukKjTHphDPGSTh h+k7oJgXF9iW2ftJ4H6M9OkuJam4ijduybSscdpNl3Pl9lEyLJ+XPXDR48WVXeimhRlv t1KM4T7bgXNmCMXcV/owC+Wj/j47QplFr+UHVfAAmRQBnGlJI8CfNGGY135+WkJceTWz lswLkChVauDg8Q0mwyPxhlumKu3HpqGr8wKyK1b1PSoZi3yG4q5BrDNTlVrZ+p4tXOV/ hRlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=P9kRGEj8; 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 p9si20003727ybk.386.2021.03.17.02.35.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 17 Mar 2021 02:35:43 -0700 (PDT) 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=P9kRGEj8; 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]:56610 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lMSac-0006y6-JR for patch@linaro.org; Wed, 17 Mar 2021 05:35:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46676) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMSU6-0001z7-2t for qemu-devel@nongnu.org; Wed, 17 Mar 2021 05:28:58 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]:39817) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lMSU0-00016A-Vl for qemu-devel@nongnu.org; Wed, 17 Mar 2021 05:28:57 -0400 Received: by mail-pf1-x42b.google.com with SMTP id x184so697604pfd.6 for ; Wed, 17 Mar 2021 02:28:52 -0700 (PDT) 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=kaO/3XjDddPfI9XqP7E0JoVJAI1xFWhKSBbTYqDo4uw=; b=P9kRGEj8r95nOVyfGoLgAjvUiNZr1RHZiuytUoHL9d7+8P1Gw/rvOHNNbYsqpIjYI9 Wz4uoLyZvg+jANcAIvczMMdSj6O3m3dmg/wdcQJg0Nu+tbpUq+IC8HJMXNtQPcUy2IAB SK3V1r6tEmf1BB+2lssC6alP6HgvyIe+kfC/XbFDbuAsYksko6sp8PzDJgWFYmnh0BLF moJDHvUKDNuDjrocWv+a65itCWQ+CS387/b4LYCDL/H+iPBvzJGlb1yJcwuptTPPmEAP RW9a6YT2oj4KgVPwPbnYoInusWDTuzbhoZdzd19Yt/BVwpg1p8FP9RT8XMzn91LRtTKT 0bEQ== 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=kaO/3XjDddPfI9XqP7E0JoVJAI1xFWhKSBbTYqDo4uw=; b=HTNsw9cdyKki3FP6OL4n7Ba+CWlD4CM9Ge4s0mfyPr+emTbDRD+Czhq1XelpT7UeOO SywP/zBXnWwGaUJ2AAzTQEeDTC9IdCI0I2GH3rCKkDFE3sovuhBGgoCe5n1Au5b0utfs rB7maiQ6zcjFFKTUIP3jrFiE9L5/qm/tP68GrgXOlvGok4m6wFOSjj0UdHOl65nbOfRW 48hz0TU8nNtyja5mRSQaIlLUVKpw6NMVbBKrfCT21zRqHIZpXmKS6JIBa9bEmyNj9ewm G34p1MBkrDDwWEba8YVCqJGwiVS7HWAE0gXbXV7ykU/nDmOlxqDeqtny4s6bxnFCMsYe 6n2g== X-Gm-Message-State: AOAM533CsI76tyijS2zE1rSIzuN+6VYy85YTf54+KH4dnehnSgcB+s7H TGnezbFvbi2kbtdTU2JkXomx X-Received: by 2002:aa7:9532:0:b029:1f8:838e:7773 with SMTP id c18-20020aa795320000b02901f8838e7773mr3426574pfp.15.1615973331737; Wed, 17 Mar 2021 02:28:51 -0700 (PDT) Received: from localhost.localdomain ([147.75.106.138]) by smtp.gmail.com with ESMTPSA id r30sm18630163pgu.86.2021.03.17.02.28.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 02:28:47 -0700 (PDT) From: Haibo Xu To: dgilbert@redhat.com, quintela@redhat.com, drjones@redhat.com, richard.henderson@linaro.org Subject: [RFC PATCH v2 3/5] Add APIs to get/set MTE tags Date: Wed, 17 Mar 2021 09:28:22 +0000 Message-Id: <5f269099f5f06c23f11d41b45d64f77eca23a8ff.1615972140.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::42b; envelope-from=haibo.xu@linaro.org; helo=mail-pf1-x42b.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 73a191f8e1..3157025316 100644 --- a/target/arm/kvm64.c +++ b/target/arm/kvm64.c @@ -1606,3 +1606,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 34f8daa377..bbb833d6c6 100644 --- a/target/arm/kvm_arm.h +++ b/target/arm/kvm_arm.h @@ -360,6 +360,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 Wed Mar 17 09:28:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haibo Xu X-Patchwork-Id: 403112 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp306396jai; Wed, 17 Mar 2021 02:33:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2azpwWEobn/zIqYZJS5FwrF8mgz09ooF5lWRG/HkZrDBzfaVvwKtDuP/EJ+JGmPQb4a9A X-Received: by 2002:a25:830e:: with SMTP id s14mr3333337ybk.42.1615973594280; Wed, 17 Mar 2021 02:33:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615973594; cv=none; d=google.com; s=arc-20160816; b=Mbs3UWniVPHr8ssv0i+cmtAsL/x0mJlh8Fzgk20mifWy9mrKeyz4tsSS903J7MAVsn nWFRRbkJ6WYiVyBr/TIAhznLXATiaWswuaO3LgEupWnext19yk5ShNUnYBrW9rgQon4i m50Dl+jQ+9rlRJlbkO5i5H6fW20QaHJbP+ejv9IVGp74m6y4JFqrJ1wVScSFbyvit/NO g5SK452WaE0ZE/Q/AxQOUbsgCESg3JTH6hw4NKP2Cg2B4TBRZPOg2ewtMZqzeUl0HE1g BxcOyN4lsCYOYwnhyMvp/DBiXfqsQCi5Y4wOF1+1cu0PCYdoE5iMGNnxhSq9+lf3Fcvr fADA== 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=cVOab/9KS4jIDkWGFjbL8+3uRQcLx+0OHUcux34L6Y4=; b=n+o1dcHHvPgUc2wQn8Wq7K3T+YyzwR5shTiHUwv1Kp8QCPIF/hZyjOsKnvsgtKFWkp 52EEGiLNbnlFhCClkiFNNO3KaThQ9OypH3dGU4bUdZ/glTjNWVcgPSuflaaXgljLo2un ckQEb0ZM9eML1iQS9fRw+5kZK4zUm6ypbPQDKTJm7niczTX60/NndaHLj8lEac+uXXQD ydWrnQTNZi1svamNlUHtFRR2OAnIg2ZRhrv5qSQmyhOvJiP3YqIKgpK+i7GgUowkr0cD a2kXeWZ3jinuv1jsYhZ1t0fH4j+SNhBvIqS6z4aFHc2IPI7FZblohHNC1IQwZaHxPkbc rx3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=CFxCfgrL; 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 n5si3571057ybf.205.2021.03.17.02.33.14 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 17 Mar 2021 02:33:14 -0700 (PDT) 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=CFxCfgrL; 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]:52170 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lMSYD-0005A1-KH for patch@linaro.org; Wed, 17 Mar 2021 05:33:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46672) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMSU5-0001yP-RB for qemu-devel@nongnu.org; Wed, 17 Mar 2021 05:28:57 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]:40393) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lMSU2-00017y-PF for qemu-devel@nongnu.org; Wed, 17 Mar 2021 05:28:57 -0400 Received: by mail-pl1-x62f.google.com with SMTP id n17so482416plc.7 for ; Wed, 17 Mar 2021 02:28:54 -0700 (PDT) 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=cVOab/9KS4jIDkWGFjbL8+3uRQcLx+0OHUcux34L6Y4=; b=CFxCfgrLzU9WJBetw50HtlW2LNEvylnyiNNVLDLZEu3si8KpqdRRobczSCF9jRKDDe O5fyw0vn4M0ulykeVWZKlEOg8hLJvIgNFxTHXNVWZPyWpGSXu6gmVY6Ma8Cj103ym5su QFe/d+qFC6ngkKCwHIb58ML6V4KCRt+ucvTttl00P0w02iJGylu6T0ttyDaTsrAP1m7V 8XrxlYjOPXKCQ61+Tl87p8FIKAam20t634kv5CcLBRuyqn+v36VaND2TD1FJC4FSB8Mu 9ALJVjhIftgK/rvenmpZd7UzjgYfm+88xrrX+dmCi4C/qJPcmmueJ6HxrCdECB150meL 2i0g== 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=cVOab/9KS4jIDkWGFjbL8+3uRQcLx+0OHUcux34L6Y4=; b=nSdg0iTH9V5g+BpVoi0dTdibdQ1Ekz3rXfeJKjtn2qxFeg+mZxWuI7vnMPwViC9oTX HmhZ5EO51BQ35EnayqC67xkQ6hGsAzDXtdaaplSOwrNcscPwzIdRNmTeL60VpFiNkxaD bMUT+0Uj765hE5jAU5MumNPwIaJzXb83u5UfePGLQQqn93WnWXWC+fGfH239SZoq1Aol dlB+E9Sr7JHZK5BTFZ7SZnLZ//5r4q5f5i7T+TFrbRxIbcqMJfhR1m5zH3/QqkbMa7VR hEWBzUmaXsA+W2vnZsAeip/Y920MFQtWeTxw9OaI3nv6fBzsUmi1ACsmr7Hv1IdHxSZp VIrg== X-Gm-Message-State: AOAM530kJV7O2NleuKga+OwZEy6aGIa1DgzWeOfM8dzXOBdmotw0pbXo tHtTJbY9w65uIfp6rtI+Y8xH X-Received: by 2002:a17:902:4a:b029:e4:74cb:7351 with SMTP id 68-20020a170902004ab02900e474cb7351mr3621113pla.62.1615973333353; Wed, 17 Mar 2021 02:28:53 -0700 (PDT) Received: from localhost.localdomain ([147.75.106.138]) by smtp.gmail.com with ESMTPSA id r30sm18630163pgu.86.2021.03.17.02.28.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 02:28:53 -0700 (PDT) From: Haibo Xu To: dgilbert@redhat.com, quintela@redhat.com, drjones@redhat.com, richard.henderson@linaro.org Subject: [RFC PATCH v2 4/5] Add migration support for KVM guest with MTE Date: Wed, 17 Mar 2021 09:28:23 +0000 Message-Id: <881871e8394fa18a656dfb105d42e6099335c721.1615972140.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::62f; envelope-from=haibo.xu@linaro.org; helo=mail-pl1-x62f.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 921416f918..8b28cde8bf 100644 --- a/include/hw/arm/virt.h +++ b/include/hw/arm/virt.h @@ -166,6 +166,8 @@ struct VirtMachineState { PCIBus *bus; char *oem_id; char *oem_table_id; + /* 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 72143da0ac..e67b798c3b 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -53,10 +53,12 @@ #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 "sysemu/runstate.h" +#include "kvm_arm.h" #if defined(__linux__) #include "qemu/userfaultfd.h" @@ -80,6 +82,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) { @@ -317,6 +322,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 */ @@ -394,6 +401,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) : @@ -1134,6 +1150,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 * @@ -1148,6 +1219,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) { @@ -1159,6 +1234,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; } @@ -2189,6 +2269,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 */ @@ -3779,7 +3860,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; @@ -3849,6 +3930,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 Wed Mar 17 09:28:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haibo Xu X-Patchwork-Id: 403113 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp307120jai; Wed, 17 Mar 2021 02:34:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSq5OmZUQsDM2/4yNjLqxOtwR3MOllYUyfRbuSo6X4XFKTDW0P09B7XnTPyOOpe7KyCvGt X-Received: by 2002:a25:bf88:: with SMTP id l8mr2285156ybk.213.1615973669892; Wed, 17 Mar 2021 02:34:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615973669; cv=none; d=google.com; s=arc-20160816; b=HDTimqmfcAuqAW4cBrkkJOVnAO0g8P9MSenEYRPpP9bz8goNZyJuMRyinME4jUkQjr qvPeOlxd0Ud+BeDM9KPz4Kn9he3B5LtqsYhe7ZF3Ue4OuJsfC5OGyUWGzlU0v8Dh2TGy AeiSnkMfyeCBdLz+Xlc9byRDlDOq34JAeWKTzi3aGRw9xMFiIXP/Mqk/KF03/yl2TQau I6a5sMQHKB1NDtNkruF+3EDrUp2rd9tdBfUf3QYLjijsOOk/u6adkDjrBEwZKuLoF4Mo 4WKyGyIzuIIht/tQIb7djy5GcgW0lLnDpX6TjQYqr4Eb7AGDaaGM3i3mQPqRMDaRZ0PQ dKGw== 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=eS//NP/1GkUCHJv2GcftGE8oA/OfSV4PaKf375lLiF8=; b=ZVHK/+pCHAv2RqxcpPS9atk5J7rV7eqS+gvLS/caNkTsBzTdRkfWh4Wyf0/YjGn+kz y17UR2lvcNIqJB7id3BmVF8kvmMGqdPdp3uaHpERUV19BT2A9AGvpGhEWwobkAmNxv9s 5X+EV4+12Pq1RapaqnloGRtjXIU03eNhlQtSV8DxD0zicXp9woxIEdbqKjjDiCJduoSD q0JnUsZx9tfEbcqdwWhdfxum8Dgojn4uvyruhB0key3IpSvN7m3Zn7LmdozQFJjBydgr wVaK32nfp9aTB9wXpdLiaklStzyBFKcCKFXCB1Uobof3iP0K2q+I/px/q9EO8UdkekZb oUqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=I6feyUlg; 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 e196si265163ybf.27.2021.03.17.02.34.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 17 Mar 2021 02:34:29 -0700 (PDT) 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=I6feyUlg; 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]:55476 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lMSZR-0006Vv-Bo for patch@linaro.org; Wed, 17 Mar 2021 05:34:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46736) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lMSU9-00028G-Lz for qemu-devel@nongnu.org; Wed, 17 Mar 2021 05:29:01 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]:41378) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lMSU8-0001Bo-0o for qemu-devel@nongnu.org; Wed, 17 Mar 2021 05:29:01 -0400 Received: by mail-pl1-x629.google.com with SMTP id a13so478641pln.8 for ; Wed, 17 Mar 2021 02:28:59 -0700 (PDT) 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=eS//NP/1GkUCHJv2GcftGE8oA/OfSV4PaKf375lLiF8=; b=I6feyUlgnb9c3fpRGeqLy5N01vjSOq/aoPvzhXFZtBz0dFGEO+a3/tAa3ca2LrnGF+ AKJr+28703SXsOL28w/962+EvZpk3ISAZ2ETCrZEEzkgHRDQB9je9lQRFBvCdiFv6Oy7 ukwIgo8wBF2zNwzQqD0wj7agX8/LMGbMSC0haKn9P6D1nhgPSE1KY0T7pMWQkjVFHagD wpnMchF8PlpRuDLWWkxpMjNZv3RJZOxibEHYNhWJjdP0bd4VlsaoozaYQ0vbwTMie9oq tKmioHcyIUGirBJJiTIrzzCg/jIzYob3TwBIhk5V8LMyxCgR8x/ooKOoThG7qOrJt8Pr Hysg== 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=eS//NP/1GkUCHJv2GcftGE8oA/OfSV4PaKf375lLiF8=; b=PjKNT/GIa/02HE2ILvjBDkwDVF6riaZA+Ner/1rNIkEnKcnL72p8IybfVbRLk+jGs3 oSv8MtXZRHWelUZjhsm//dDZBnEfSZZrmmxJqQBPNewtWZaeholM1wNYJ7Egepv9p9sJ zcEr67mBV4QxNbPJET3gRen+T50ont1AcS4w+7+Tzw7jPmITLO8QyNOBTRQmjO7vM5PN nLzsPxhB3ZCX6guJD+VHFzUvwH1bla9ZVWxBbyIXldBTrrJ8xHb2I3zgREpxl3P5fk8V 3mW10NxGlITvaKUQTR2isjemGWXz1GwTrtBfPB9DjXXX00Etxm9JXt04J7CNMgCLsJp/ 0pYg== X-Gm-Message-State: AOAM530Ii5yFJzGhgaZecSm0CaU5w433mZaYA5PScLIxhhmFclbar7UI 6mr7Ypn4cyTbf6znD5JaqKLV X-Received: by 2002:a17:90a:840a:: with SMTP id j10mr3475362pjn.97.1615973338789; Wed, 17 Mar 2021 02:28:58 -0700 (PDT) Received: from localhost.localdomain ([147.75.106.138]) by smtp.gmail.com with ESMTPSA id r30sm18630163pgu.86.2021.03.17.02.28.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 02:28:54 -0700 (PDT) From: Haibo Xu To: dgilbert@redhat.com, quintela@redhat.com, drjones@redhat.com, richard.henderson@linaro.org Subject: [RFC PATCH v2 5/5] Enable the MTE support for KVM guest Date: Wed, 17 Mar 2021 09:28:24 +0000 Message-Id: <5ed81ba84e44100798009cee95c3dc2d993602f0.1615972140.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::629; envelope-from=haibo.xu@linaro.org; helo=mail-pl1-x629.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" 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 76658b93a3..36cfdb29e9 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, \ @@ -828,6 +829,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(char *fdt, DeviceState *pl061_dev, uint32_t phandle) { @@ -1912,9 +1928,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);