From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sean Christopherson Date: Thu, 1 Aug 2024 11:01:30 -0700 Subject: [PATCH v12 02/84] KVM: arm64: Disallow copying MTE to guest memory while KVM is dirty logging In-Reply-To: References: <20240726235234.228822-1-seanjc@google.com> <20240726235234.228822-3-seanjc@google.com> Message-ID: List-Id: To: kvm-riscv@lists.infradead.org MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit On Thu, Aug 01, 2024, Aneesh Kumar K.V wrote: > Sean Christopherson writes: > > > 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 > > --- > > 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; > > + } > > + > > > > is this equivalent to kvm_follow_pfn() with kfp->pin = 1 ? No, gfn_to_pfn_prot() == FOLL_GET, kfp->pin == FOLL_PIN. But that's not really relevant. > Should all those pin request fail if kvm->nr_memslots_dirty_logging != 0? No, the conflict with dirty logging is specifically that this code doesn't invoke mark_page_dirty(). And it can't easily do that, because there's no loaded ("running") vCPU, i.e. doing so would trip this WARN: #ifdef CONFIG_HAVE_KVM_DIRTY_RING if (WARN_ON_ONCE(vcpu && vcpu->kvm != kvm)) return; WARN_ON_ONCE(!vcpu && !kvm_arch_allow_write_without_running_vcpu(kvm)); <==== #endif From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 658BB14374F for ; Thu, 1 Aug 2024 18:01:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722535294; cv=none; b=Umq4cse8apMOAEUTGBy1NE9m0/ajY00mzHgNQJRvNvgJ/omF3E0YHoG28StF/72KSeKKDOrXPODSuhpxBWigiCnsLTd/S7S2WOPIlRzMg77+k6TNaqzlgmCTVwsp/V8/CLnroMK8rNVBreOHElv70Q3RCAtmApGdmGCc1rlMk2o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722535294; c=relaxed/simple; bh=B4USJ3DcoEtC2grgJaNeehMjrX/R6yyLoOz0nwuEw9c=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=sCYzOOq/lWYxSdUt5TRv0M2ysvO2DKO3vlqFQCM9iHpoJ5fPOivT+CTm38PM+dSmhYzQXhsQydlmc/ul9DM8haOAtVNov2q5DiSnnfFKzkUyrQk+SwK0n8L/xOnaGaz6fCuoOpS2IqKIojrzlzEur2c+hiXBzK6B+FLXpmJnlUQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=4moarI/e; arc=none smtp.client-ip=209.85.215.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="4moarI/e" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-7a28217cfecso7441116a12.2 for ; Thu, 01 Aug 2024 11:01:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722535292; x=1723140092; darn=lists.linux.dev; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=xl2Pju3NY9Fnm1xajnPNr4ZOFDET+sfv7XV8JXyIerc=; b=4moarI/efjsuhWG1RgrJl0p8ZHZ3T7DeYTEUR5q5CwH3okgTbbhOwjsdV5coFVbyCO wG6IAnlwtcJGVtJ5w0ag5f3AIsIapjuYNQsasHFHKp9eI+A9URbCb+O0LEdoa3/FCrxB EsDDugHkFSVWjXI/PjFZjaP9T2qUc6nItlLefNlWOoXtANyv1Z7PlWe/+cxWIhCr3CQ1 Z5WmKHvDwOnyABHEiKAs7Uqh+IGS+EgH9Ew+DC3tl0zScVWwWL78x4F6Ovzp0K80GbTR 2SZ4P1uH4UL6QYcHFgVo9SdjK0r+VnGb76SbExvYPT3bN/UXth16B/ceHH+LWkEZdcsF DwBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722535292; x=1723140092; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xl2Pju3NY9Fnm1xajnPNr4ZOFDET+sfv7XV8JXyIerc=; b=Hbd+rsKFRlXkJtKyCX2IVVNjP5owe2bJUZMPmPORpuva1ZdpBUwHM3V9EgDyDrft7d qPjRm6xcmRyKr8xcM2SgRs+DH5xANowXa74kRcx1q9N4bUMX5FalB3QKGtPEU+GhkGO3 TUMMg4d9RA4njX2SVCn+DIiroxpmFsdzk73cVyUeVRaPgcE9623Ony7uf5hL7wOZSN8R AOt3CEcx4+SOkzy102qcHOAcqlmyVZZqQzE1oG2E500JzFOxY829jA51hmyIGXH4Ojcc uYhRRu5wumw4+Q+2tAGmczieHjatXxX+yj368LnqF31AxJWZq6mdLyePRG8t9ZmEk/3S pNLg== X-Forwarded-Encrypted: i=1; AJvYcCVluDStd2WqhJ604CfmC2wg+3RsbE3UfFkK1k2fA5f5IvfWb4m3DewRCtlrhx7Va7MDTOZF72OF+5XhXn6FiXZo0GemkHdb X-Gm-Message-State: AOJu0Yy8LUWpXC5Lux+8yTTjXCm6IX+lnxTgdZnEZjxOvhz4LyNm0owD zODK+u+TaTor9zNpyz1flupBvnCbmnvg3yp+Dw6vDCCleMd3zIPnKg4Jx/R0Ik1lLXpK7/ZDgRg BIg== X-Google-Smtp-Source: AGHT+IF64U8Ib+bNIe3iPxoSzJOvvilQGXPjPZq7Y/8acNPwlcg0hACHnvmYPGnFv3dx9aufX4l27GJDySU= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a65:6252:0:b0:75a:b299:85b6 with SMTP id 41be03b00d2f7-7b74669c7b3mr1534a12.2.1722535291408; Thu, 01 Aug 2024 11:01:31 -0700 (PDT) Date: Thu, 1 Aug 2024 11:01:30 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240726235234.228822-1-seanjc@google.com> <20240726235234.228822-3-seanjc@google.com> Message-ID: Subject: Re: [PATCH v12 02/84] KVM: arm64: Disallow copying MTE to guest memory while KVM is dirty logging From: Sean Christopherson To: "Aneesh Kumar K.V" Cc: 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 , 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 Content-Type: text/plain; charset="us-ascii" On Thu, Aug 01, 2024, Aneesh Kumar K.V wrote: > Sean Christopherson writes: > > > 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 > > --- > > 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; > > + } > > + > > > > is this equivalent to kvm_follow_pfn() with kfp->pin = 1 ? No, gfn_to_pfn_prot() == FOLL_GET, kfp->pin == FOLL_PIN. But that's not really relevant. > Should all those pin request fail if kvm->nr_memslots_dirty_logging != 0? No, the conflict with dirty logging is specifically that this code doesn't invoke mark_page_dirty(). And it can't easily do that, because there's no loaded ("running") vCPU, i.e. doing so would trip this WARN: #ifdef CONFIG_HAVE_KVM_DIRTY_RING if (WARN_ON_ONCE(vcpu && vcpu->kvm != kvm)) return; WARN_ON_ONCE(!vcpu && !kvm_arch_allow_write_without_running_vcpu(kvm)); <==== #endif From mboxrd@z Thu Jan 1 00:00:00 1970 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 AFAE8C3DA4A for ; Thu, 1 Aug 2024 18:01:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=P56eaWav/yNlQ9XmS+dZ6ztqkei1RNxva1ZrRwRAqTg=; b=wxmL8Ripa4Zm5+vvM2OQqkwASI 1EEiYR8zYzhDrEWARHnGpPEc6jNgHPp+ZHJdjWyWDibeawFJhzazz6m0Jiz8u5QXboN64+TF6p8hp Ek2BPb8oTRoZdKotHotlrp3An1pZJe8H//tqxxFqigtwOLDrKy4eK2XmP5m9ud6z/LrMpR2t3yTai WqI2GM+RpCuMILI3H6MaTzPKm68XB+LX4hMlqVx6fuSXzrJmIheiFIGFDFk1h/6jid2LbcaWOt6Ky dM1HoWu+yy2hDduMAjsNIqFUH61uMuaMo0gVU9PHrR/vcXLQUPduMsOjHIetwC1f3XIrJKZX4m/zZ kzC6FTSw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZa7M-00000006Kww-08dL; Thu, 01 Aug 2024 18:01:36 +0000 Received: from mail-pg1-x549.google.com ([2607:f8b0:4864:20::549]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZa7J-00000006Kvf-0MpA for linux-riscv@lists.infradead.org; Thu, 01 Aug 2024 18:01:34 +0000 Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-7163489149fso7121678a12.3 for ; Thu, 01 Aug 2024 11:01:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722535292; x=1723140092; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=xl2Pju3NY9Fnm1xajnPNr4ZOFDET+sfv7XV8JXyIerc=; b=aQu0+UwbG8BXEUc8XDf29o2aZ0+j4j3tTNEO1v5CDh+5j6VpC+LqyVnVLKjCyGvf42 yfTHyoMEW+m4JV4vj+GNm2/j5BVY+mQJQM7jN2C1LS0W9BjsdOGRlmPuvvc7G4393qL+ Kuch1GO2hcl2XdT3KDMiH4a96WrLnsgvlz297gYxYgyShOauiFgJkTTQHY03/zf5+Edw ghEOwVHu4Y0qC1q8UEXQkJ2TY1Ze6U4k000u3aMjKg1T3AJ3jIWIX5qAJhAVoNl/Xfq5 3vbOSlKK4jjUeY5F6ThfbJGOCCcsr0WwlIhZqXc555eGK+c6E+mrXaHexQ6hfHuxGDL1 VZ2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722535292; x=1723140092; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xl2Pju3NY9Fnm1xajnPNr4ZOFDET+sfv7XV8JXyIerc=; b=Bs787peVyBz9tbxZSsd0GF/Ygcn4sHezapaU+NlWrG8SQ34Ao6uj+Y3ci2/OjRJQ6u TG1pVYYrMArNJTk8XQsP7aC1//QXxo7oG+sm1niUBP3Idqk5AqDjh5nVTcEnb6zqG+FZ ii/ISCGSF/plIXsc0Fq2Cop0uq8jYjQskDJwAtOB1IK/G4Z5+LG9ZRfL9dh74Ww/7m37 FCHzvBm8jv3iAga148od7lk3T1KAojNggG63BJX6yqGZf8n7ypPeoYl9X67kjkCEZ/LO n5wRoeHAK4GNlz5AKW1sLeJs4/PpInzaEKkATLVc02oJyLaFrn/3DQtpgkDinA0ewX/+ qYJQ== X-Forwarded-Encrypted: i=1; AJvYcCVIEkvTzGrwqj2teEiNEZc7p7IVGGCcapjQkW7B12qaRtZ2POrQJzmEoDPH0EhprqkIugDw/JejxogTnxr9VIa6jBKu9sSRY00SC+KniGPk X-Gm-Message-State: AOJu0YyMhUPob4Nos/BqwJBDy23nCCssLk0RBlvL0f+1J8eTAe2VzZB5 +xxEQ4ZV85xBBeuAPkgcaI164gC6Jc+27tnaLW2hutMyIt4e81kfpdJ8GngXVEo5yTpVA0WCPrA jtA== X-Google-Smtp-Source: AGHT+IF64U8Ib+bNIe3iPxoSzJOvvilQGXPjPZq7Y/8acNPwlcg0hACHnvmYPGnFv3dx9aufX4l27GJDySU= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a65:6252:0:b0:75a:b299:85b6 with SMTP id 41be03b00d2f7-7b74669c7b3mr1534a12.2.1722535291408; Thu, 01 Aug 2024 11:01:31 -0700 (PDT) Date: Thu, 1 Aug 2024 11:01:30 -0700 In-Reply-To: Mime-Version: 1.0 References: <20240726235234.228822-1-seanjc@google.com> <20240726235234.228822-3-seanjc@google.com> Message-ID: Subject: Re: [PATCH v12 02/84] KVM: arm64: Disallow copying MTE to guest memory while KVM is dirty logging From: Sean Christopherson To: "Aneesh Kumar K.V" Cc: 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 , 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-20240801_110133_149652_F022DEDE X-CRM114-Status: GOOD ( 19.79 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org On Thu, Aug 01, 2024, Aneesh Kumar K.V wrote: > Sean Christopherson writes: > > > 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 > > --- > > 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; > > + } > > + > > > > is this equivalent to kvm_follow_pfn() with kfp->pin = 1 ? No, gfn_to_pfn_prot() == FOLL_GET, kfp->pin == FOLL_PIN. But that's not really relevant. > Should all those pin request fail if kvm->nr_memslots_dirty_logging != 0? No, the conflict with dirty logging is specifically that this code doesn't invoke mark_page_dirty(). And it can't easily do that, because there's no loaded ("running") vCPU, i.e. doing so would trip this WARN: #ifdef CONFIG_HAVE_KVM_DIRTY_RING if (WARN_ON_ONCE(vcpu && vcpu->kvm != kvm)) return; WARN_ON_ONCE(!vcpu && !kvm_arch_allow_write_without_running_vcpu(kvm)); <==== #endif _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv From mboxrd@z Thu Jan 1 00:00:00 1970 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 lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 2098DC3DA64 for ; Thu, 1 Aug 2024 18:02:18 +0000 (UTC) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=tqipnU2F; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4WZcHX5L6Mz3dW8 for ; Fri, 2 Aug 2024 04:02:16 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=tqipnU2F; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=flex--seanjc.bounces.google.com (client-ip=2607:f8b0:4864:20::549; helo=mail-pg1-x549.google.com; envelope-from=3e82rzgykdaiugcpleiqqing.eqonkpwzrre-fgxnkuvu.q1ncdu.qti@flex--seanjc.bounces.google.com; receiver=lists.ozlabs.org) Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4WZcGl6959z30Wc for ; Fri, 2 Aug 2024 04:01:34 +1000 (AEST) Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-7a23a0fb195so7397196a12.0 for ; Thu, 01 Aug 2024 11:01:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722535292; x=1723140092; darn=lists.ozlabs.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=xl2Pju3NY9Fnm1xajnPNr4ZOFDET+sfv7XV8JXyIerc=; b=tqipnU2Fzxk8dDfkeB/IkKdFGgviVP9Vn9bgiEO0vmSP7SXvhKBQupRSruSwp/qEZI NoISbCQO5AlKR0z2rTXwaXsIjtCcb/pe74C7fA3e2zkvPWAsuImAkdNWJZz1Sd9SYIOU GZyAhcUCR5czfpPEtDo+u2Zm29whFculWpkaksQonMk/N7wkIdX6FEFTh92mXMwEg8Rq IHOnr4tg4QHQjrbBa8K5obElXVkyRysG+b2Kxl6GPN+z5YyxxfjwP48N63rdyjWM785E jxIESNfyNOezeZZVyDp1OhjDPQ4WvGh/5h3A+EK8kCFZUI8twQqe532AAqaHqEXzQ6JH LIRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722535292; x=1723140092; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xl2Pju3NY9Fnm1xajnPNr4ZOFDET+sfv7XV8JXyIerc=; b=Q8/LHW43MXEEI2v3eJs138nJW1wshY6wcs1x6MqF8w2unX9kEF7B1rg4H8VDKram0n uZeuDSXLC5fYKzfs/V7Gl+ilXOkDvMC7iDmb/aCCG/8KIcfl4kCAxefjYRPGIZ8ffd1q Fxy/rRVQ6iMHmJiQlhixsW9W5BvgU3jFkg0zw7tlipPTEq+KcfeWZAGrja/3E597JEPW isnzvYv04UTVcSKjLZH6znQaqgaZQJ/PeZ6lknnRHkh4bMkBAP/TsWMUpVAxECnPZfb5 eG61q5vhTnRWqm75vOLUBdJcbdUorUQSShGwjyeqDEVnK59FeTgYvNZ+9gz14+H9R1UX C3pg== X-Forwarded-Encrypted: i=1; AJvYcCXmJEFalriPh3kiTGV2NpeNfGGzMNDNZpWla2mtJwMMZqxM500jkE2nkPCsLiuS9fW9VzBsoSW/NN/kUMQBiyOkpN09zBwqYRBbgnKyKA== X-Gm-Message-State: AOJu0YyQiTYOVMVxZNIqNHXsQjbPO0zDNSNj5IUdpmG+MFhBkGxZiCyt NJEVZ3Dmzwllo7eQQlKfUUd4g3Gd45OmGRsRibrRpUpKEUWtD5KC+XGIfeI9CnOxWkb8VwPB+/j SNQ== X-Google-Smtp-Source: AGHT+IF64U8Ib+bNIe3iPxoSzJOvvilQGXPjPZq7Y/8acNPwlcg0hACHnvmYPGnFv3dx9aufX4l27GJDySU= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a65:6252:0:b0:75a:b299:85b6 with SMTP id 41be03b00d2f7-7b74669c7b3mr1534a12.2.1722535291408; Thu, 01 Aug 2024 11:01:31 -0700 (PDT) Date: Thu, 1 Aug 2024 11:01:30 -0700 In-Reply-To: Mime-Version: 1.0 References: <20240726235234.228822-1-seanjc@google.com> <20240726235234.228822-3-seanjc@google.com> Message-ID: Subject: Re: [PATCH v12 02/84] KVM: arm64: Disallow copying MTE to guest memory while KVM is dirty logging From: Sean Christopherson To: "Aneesh Kumar K.V" Content-Type: text/plain; charset="us-ascii" X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, David Matlack , linux-riscv@lists.infradead.org, Claudio Imbrenda , Janosch Frank , Marc Zyngier , Huacai Chen , Christian Borntraeger , Albert Ou , Bibo Mao , loongarch@lists.linux.dev, Paul Walmsley , kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, Oliver Upton , Palmer Dabbelt , David Stevens , kvm-riscv@lists.infradead.org, Anup Patel , Paolo Bonzini , Tianrui Zhao , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Thu, Aug 01, 2024, Aneesh Kumar K.V wrote: > Sean Christopherson writes: > > > 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 > > --- > > 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; > > + } > > + > > > > is this equivalent to kvm_follow_pfn() with kfp->pin = 1 ? No, gfn_to_pfn_prot() == FOLL_GET, kfp->pin == FOLL_PIN. But that's not really relevant. > Should all those pin request fail if kvm->nr_memslots_dirty_logging != 0? No, the conflict with dirty logging is specifically that this code doesn't invoke mark_page_dirty(). And it can't easily do that, because there's no loaded ("running") vCPU, i.e. doing so would trip this WARN: #ifdef CONFIG_HAVE_KVM_DIRTY_RING if (WARN_ON_ONCE(vcpu && vcpu->kvm != kvm)) return; WARN_ON_ONCE(!vcpu && !kvm_arch_allow_write_without_running_vcpu(kvm)); <==== #endif