From patchwork Fri Jul 26 23:51:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13743431 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 19620C3DA4A for ; Fri, 26 Jul 2024 23:55:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Reply-To:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To: From:Subject:Message-ID:References:Mime-Version:In-Reply-To:Date: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=+ACqpXiHFW0htcnePdxx7jkBXYAkQBnbtzPYGP86yy4=; b=z07N+c/ZgH9qYudoOQtiPVSOT1 mxv+ZadaFJyajmOEVgkPZOOYh3VAhfex1ZLULtKwfxoRiDNmwbwjIpDLvdms0SclnkLGoBWBqSx2u mI5wR24bfGydIv8EbNhIgTNhoIsYeOEn/02P0J8APPZZzE0uzuGKEBrHV6gqCRDBryAkXovllTbrh W/Hld+3WoX5JDKnYh7RzHmkjv6X+Xy4dFW9FWNVxj4fBDjJxkur8rR0Ie9qjlXDXsBH5Dmbig+ANM QMjgola89cuBt/7idOBRr42fkkvcpfAHmTfot0iYCFg3DOJd8Lm3WAyV9scBL6nE4lYD38aPgC0kV u+zoccDg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXUlu-00000005Quv-3iIQ; Fri, 26 Jul 2024 23:54:50 +0000 Received: from mail-pf1-x449.google.com ([2607:f8b0:4864:20::449]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXUjr-00000005P9S-3hta for linux-arm-kernel@lists.infradead.org; Fri, 26 Jul 2024 23:52:45 +0000 Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-70ec1039600so1045943b3a.0 for ; Fri, 26 Jul 2024 16:52:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722037962; x=1722642762; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=+ACqpXiHFW0htcnePdxx7jkBXYAkQBnbtzPYGP86yy4=; b=GUTcAD7G/IEqTQBDwkN0d+unfvHGOHtzepTk0k95GMmhpmyt55Pg0jbDr4Vxu9pMJz 7i/T07LhY03vJfzAA+439QiKhl8X5SShXNeN868QZIhkErIsJyT+ss/dCjKaUag5OZtQ p9rekki1UeXULTwmdrwX//WA5aLj0VL/CMQDdyWyFwNltswQbAbH6b64kCNQueyqZvtm 3FZ4a66QnzSO2wts4NY1YQVRF7HOACiCoXrkqxN/2B1v/TcsJOqXQfOEkmS3L1mZPmDU G4uuRvFHpaWCQMqoISPEklRLd3IWS9MqbUKF9qw6l9L+JOKYFkbgSD9AfnCgu81FV0wf kQwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722037962; x=1722642762; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+ACqpXiHFW0htcnePdxx7jkBXYAkQBnbtzPYGP86yy4=; b=o78lbvSZi0Bxgc1MuwmyiUuFzqqgwW/+Uz5F5A+WSzHuWzAWpTwnd84eJXkKpAzAHC WwUIPHIx1hnBBxlZyzrqlU+d/6qRroRMx1AqVyeDteeNWngcKJz7YVd9TjT/FPjW/FdB C8AuV0S1nlSuem64L8rEJrpUvOkViGtWiz7jzb1rQMi/KCpLzmtvY5Dg7sxbonxotuhV TQBYiaCIyzGlxT6LlhrVKnS7PZq6aVoUVLW4EDGbJ57F+isaAqjo07qFtcoXlyZXgFhp 06CymIHWoKNhN+8if/5FyX2a0Wa9jhf3diyxqMb2Jm1t5+m/amnjfxVEtDVgdORiait8 kXqg== X-Forwarded-Encrypted: i=1; AJvYcCW+WV5YCsB5WfCABs3Ue7UnDmRR05rZHBn9hEG1gdhQnEhn/MNzSAAKI9G7NMut4gsX9j8mkWeZPsWEgZ4t10N234Zp28XAko7DZwbWSwdhcLvja/o= X-Gm-Message-State: AOJu0YzH8eOv3Jx6l3pKHhV6DfephZgCHA9kHd8jeUF8PGH5Yt/swaYk 5L+1wujxhXGA412oMc8P3oCnvQg0Dy0dM89ztWcfxA9c7KzN/8zbITOrLz0/AJL+vlnz1gYjBh8 Z3A== X-Google-Smtp-Source: AGHT+IGwCQGQqihWYa2umPunvMXl+38XfICaGVr07aRfeEr4UWXG0owvMV5oQenmn7mjdAWrLBWC2Kt2f3c= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:2d5:b0:70d:1cb3:e3bb with SMTP id d2e1a72fcca58-70ecedee1c9mr17317b3a.5.1722037961972; Fri, 26 Jul 2024 16:52:41 -0700 (PDT) Date: Fri, 26 Jul 2024 16:51:11 -0700 In-Reply-To: <20240726235234.228822-1-seanjc@google.com> Mime-Version: 1.0 References: <20240726235234.228822-1-seanjc@google.com> X-Mailer: git-send-email 2.46.0.rc1.232.g9752f9e123-goog Message-ID: <20240726235234.228822-3-seanjc@google.com> Subject: [PATCH v12 02/84] KVM: arm64: Disallow copying MTE to guest memory while KVM is dirty logging From: Sean Christopherson To: Paolo Bonzini , Marc Zyngier , Oliver Upton , Tianrui Zhao , Bibo Mao , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, David Matlack , David Stevens X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240726_165244_003958_7EB703A3 X-CRM114-Status: GOOD ( 11.21 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Sean Christopherson Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Disallow copying MTE tags to guest memory while KVM is dirty logging, as writing guest memory without marking the gfn as dirty in the memslot could result in userspace failing to migrate the updated page. Ideally (maybe?), KVM would simply mark the gfn as dirty, but there is no vCPU to work with, and presumably the only use case for copy MTE tags _to_ the guest is when restoring state on the target. Fixes: f0376edb1ddc ("KVM: arm64: Add ioctl to fetch/store tags in a guest") Signed-off-by: Sean Christopherson Reviewed-by: Catalin Marinas Reviewed-by: Steven Price --- arch/arm64/kvm/guest.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c index e1f0ff08836a..962f985977c2 100644 --- a/arch/arm64/kvm/guest.c +++ b/arch/arm64/kvm/guest.c @@ -1045,6 +1045,11 @@ int kvm_vm_ioctl_mte_copy_tags(struct kvm *kvm, mutex_lock(&kvm->slots_lock); + if (write && atomic_read(&kvm->nr_memslots_dirty_logging)) { + ret = -EBUSY; + goto out; + } + while (length > 0) { kvm_pfn_t pfn = gfn_to_pfn_prot(kvm, gfn, write, NULL); void *maddr;