From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sean Christopherson Date: Mon, 5 Aug 2024 15:09:21 -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 Mon, Aug 05, 2024, Aneesh Kumar K.V wrote: > Sean Christopherson writes: > > > 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. > > What I meant was, should we consider mte_copy_tags_from_user() as one > that update the page contents (even though it is updating tags) and > use kvm_follow_pfn() with kfp->pin = 1 instead? Yes, that's my understanding as well. However, this series is already ludicruosly long, and I don't have the ability to test the affected code, so rather than blindly churn more arch code, I opted to add a FIXME in patch 76 instead. https://lore.kernel.org/all/20240726235234.228822-76-seanjc at google.com From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.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 B6ADF1662FA for ; Mon, 5 Aug 2024 22:09:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722895766; cv=none; b=Z1eQbxHUND/60+bPpjaHWXI6q+lgNzmpF7FSvJiBRdf5JH4LTzQAkK/iwGMeB8h6IzVKHBDVUQASlfafSgrH76G0ehhByfZ4kZrFpSixGXOvvcIy9iNnFI7LTXNJWX5Vb5dahfkEIcV3pDEf6x5RZbuXGJDfN0GJIjRmbbn5zYI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722895766; c=relaxed/simple; bh=dmDvoV7DR66fW1rp/kKa2yAHHnKdcTd2T9VoWrRsnCs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=povm9c9ikSFINb+N4HVj39onMtyg4cXkleLUL6jo7rDP1TRqe+TPIGh3CTxA0U+iZz+8rIxG/UbtOZh1mpG60MneGlqcIsB6navUH0+gTY6jEn2mxu1L4Xn0EhUgBvf+Gjv+pKQwRTerBlMoPQ+/2vtGe7zBFg3vEOpDZ3dxCGE= 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=DLw/Q3TY; arc=none smtp.client-ip=209.85.210.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="DLw/Q3TY" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-70d1c8d98baso10003219b3a.3 for ; Mon, 05 Aug 2024 15:09:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722895763; x=1723500563; 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=C2PiU8MTrEuvmn4oJRZEcNoPreaY/lLc5L+V0JuLroE=; b=DLw/Q3TYHOirric0vxX16GEYtS/bNyLHuuPbuRjWd7vbxaWjxtCg8YFmRPQWSW08PC GTR22DAGBFzMK/xZp+nc1aLRxigiWszgBXKy8cch22DiY1gN4CBSE2DFMOPRJhLAG+CY nP2bSAiy+Uvb9N5p63WgtYkmEhleGDywDvhbRI7F0umGday5nBVtqA4rFl3Ka5UQcoM8 z2cBYZZANu9HXOrf7w80mNuV96/9mTqQNkk/JpvT+pWa+59UKRU328s0X7qjSRmKqBoS 71LTFs4D4b8U3dXF5hFmkL2732Z1fT7TZKCtzkB5QyX10DW2p2GYXskyvtXZvMWoSkCM BhxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722895763; x=1723500563; 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=C2PiU8MTrEuvmn4oJRZEcNoPreaY/lLc5L+V0JuLroE=; b=h+jCqnOMp7kMd7mYFyO+6T+pCBaoWYL08zToXSFW9IwDTkpfE5FtxnHaKgf7Rvglkb gw4g/JpJYjnUT3C8g86BqlqbR2xAJuaoLYi4rex+qS5pbTWpufVyfJVPQulSZ0xME5CV W5XJCUfqALCFGVzF7/Mjo3yup7/SnEob19k8PTxjA3CK8IUqIkaraZlWxwhBd938UWfX sCeLYE6gtN4LHKgFRIY2da01gmaZrqzhcMvA/DUnDm5farlTCEHIa+Ylo5KQLeKJOkmw vliJTefsbgyDTM8IItrOOtqsYVHs/4LQxjCEauoM1IGIvHFgS0hZ/sXcb7/583thRamB /9HQ== X-Forwarded-Encrypted: i=1; AJvYcCX2Eb+pFOm3t7RAaXZ1WPslqj3rBAmIS0Oudw8m2YmY7B+pRVqzgwFZAMV7SY8mcPYvOGZNKD/+2kehshaPT6jWXk+BK4JG X-Gm-Message-State: AOJu0YxTojHudsl8QFbbAkxPFcUXIHaXYMvrkK2Gl5w0Jegpxrzqr8x9 ul9ayCwshFO4Y0xyQIkKJLOKsoXVXHDLRTrqxyqaTw7WtEXZuoLj2V3Z0EhDGTbPUvTK4dgn4Ev oVA== X-Google-Smtp-Source: AGHT+IFHGqnQ2aZELEsNF/YUFUu/OdaSqANvJ2o5+KNT08fnEczrxRkzi5g08NacDnyiiIzp3YSr6oxKzK4= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:6f0e:b0:710:4d08:e41f with SMTP id d2e1a72fcca58-7106d08296emr87588b3a.4.1722895762937; Mon, 05 Aug 2024 15:09:22 -0700 (PDT) Date: Mon, 5 Aug 2024 15:09:21 -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 Mon, Aug 05, 2024, Aneesh Kumar K.V wrote: > Sean Christopherson writes: > > > 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. > > What I meant was, should we consider mte_copy_tags_from_user() as one > that update the page contents (even though it is updating tags) and > use kvm_follow_pfn() with kfp->pin = 1 instead? Yes, that's my understanding as well. However, this series is already ludicruosly long, and I don't have the ability to test the affected code, so rather than blindly churn more arch code, I opted to add a FIXME in patch 76 instead. https://lore.kernel.org/all/20240726235234.228822-76-seanjc@google.com 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 1F1ECC3DA4A for ; Mon, 5 Aug 2024 22:10:07 +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=UW5uIbUvtW6Gl1Fmfifo0tcIpHiqclOu6hN3jyNxiGk=; b=jdDM1pc/QtSlppiyGzGyxEpI8n 6j9UHXt1ev0EnJorUOhR7zjajImG44++8V9UXDqHhPipByshJRVJRTNidX/Wm9LyZo6ZvhWxbIp+y Sqzxwlvse3/pPzEk2+tjYdFX04eSxY/A+9QJTVfL0KbNVHkV+b3MXm8kqgyNX+lf0gue4TJm93/Tq WXtUSAhpYfmr6JhHLq/gt1vSXKonYsUnssk02LrCU2yyHy5oVOCi9G/p2qCpAjxjarKCYkUFmiFjz t0/p7fNrWceZRLwEbBwacJNj1lK8tESatqHIqspKymzOFNMybJFXM9Qz7ZhquhshUbXqtSQe8osx9 pCEqYwPg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sb5tu-0000000HQHz-3oir; Mon, 05 Aug 2024 22:09:58 +0000 Received: from mail-pf1-x44a.google.com ([2607:f8b0:4864:20::44a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sb5tM-0000000HQ7W-31AJ for linux-riscv@lists.infradead.org; Mon, 05 Aug 2024 22:09:27 +0000 Received: by mail-pf1-x44a.google.com with SMTP id d2e1a72fcca58-7106fcb5543so3132814b3a.2 for ; Mon, 05 Aug 2024 15:09:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722895763; x=1723500563; 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=C2PiU8MTrEuvmn4oJRZEcNoPreaY/lLc5L+V0JuLroE=; b=115nYEdRclej89a+1jgGo7pRGhtbQQfLhl/xoyMti8o6mzKAOYsl+70srkjAaT1ZTc 8yE1m2vdHqta1EDgYa2f69T9nG+S7WuXj9ZxPPRF9RrXxygTG2u7Wzk61CEP2ZURP41K TvkBkU+EYLga5Dkod9iRNw+udFADUOSojnD+u+/m3FAldXSpdyp2p05v9DVrYzHlZVid wI67tInY/EENIR1OLNBGdVI99xuj4lekCEhaeDMfRO9pqB5j5b7SU//iBtTC9gBbB2BZ YOLbJ5yG0gvMJuCitbLd8zSez2kh6O71y2N1f9+NVQE8eYIhVJKF4L1ZqcUH/KGH/YKu IEnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722895763; x=1723500563; 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=C2PiU8MTrEuvmn4oJRZEcNoPreaY/lLc5L+V0JuLroE=; b=UwL5QB22ij37rBC7K/3OLFwbUv0bohogAOluP1Eoqk235ePbZXmL2ZPPc0w9MIJItr L6UnrIoq8LNDYrgNTUpdxEfrkbNeC/dHTk/FfoXOBwG9Lz7ObzWtgHY+bIUn1E2ovMbT GRIx14ZvuTS0DDo+fJc7JgpBQh1bKKiz5PPmRPuv32H1EdZ0A8eLgWlEQw7sZbkvJ2IY DBCfQS88vx5kQg+6A/vSswn0nbe7huxPPACcZ3/JOXnun5InDu3y394Eq+TiT3RUETl3 bhEe6U3cdhvZQlQJl1ek0yEKdJZ9IIDLrOgfXLjFeifqHnK1Hdg3bciXZUjPib6rL40t DsRg== X-Forwarded-Encrypted: i=1; AJvYcCVk5gvLX9TbUl4owa85K1/A9tdiLyuRdXLUDUmmAdugL6bdpOINuB5fJbcBI+9udilWGBQzkB1QgCghLSRtwIDsKhrJm8ywPDEkeIqkTCYx X-Gm-Message-State: AOJu0Yzzrfhxflnjr3lWY/YJVPr9C7QGfYmXJjM3MSicRwqtcobY/wE8 SLtN8Vn+l4zGESQlemBCo9zaiH0tINInLqyE4Lv8H7yiX46v7oZqpW6177UXtbC7V0bkZ+HOD8S 3EQ== X-Google-Smtp-Source: AGHT+IFHGqnQ2aZELEsNF/YUFUu/OdaSqANvJ2o5+KNT08fnEczrxRkzi5g08NacDnyiiIzp3YSr6oxKzK4= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:6f0e:b0:710:4d08:e41f with SMTP id d2e1a72fcca58-7106d08296emr87588b3a.4.1722895762937; Mon, 05 Aug 2024 15:09:22 -0700 (PDT) Date: Mon, 5 Aug 2024 15:09:21 -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-20240805_150924_782094_3F11091D X-CRM114-Status: GOOD ( 22.54 ) 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 Mon, Aug 05, 2024, Aneesh Kumar K.V wrote: > Sean Christopherson writes: > > > 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. > > What I meant was, should we consider mte_copy_tags_from_user() as one > that update the page contents (even though it is updating tags) and > use kvm_follow_pfn() with kfp->pin = 1 instead? Yes, that's my understanding as well. However, this series is already ludicruosly long, and I don't have the ability to test the affected code, so rather than blindly churn more arch code, I opted to add a FIXME in patch 76 instead. https://lore.kernel.org/all/20240726235234.228822-76-seanjc@google.com _______________________________________________ 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 02210C3DA4A for ; Mon, 5 Aug 2024 22:10:10 +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=xCEcxFHW; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Wd9bj3pHFz3c75 for ; Tue, 6 Aug 2024 08:10:09 +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=xCEcxFHW; 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::44a; helo=mail-pf1-x44a.google.com; envelope-from=3kk2xzgykdc8dplyunrzzrwp.nzxwtyfiaan-opgwtded.zkwlmd.zcr@flex--seanjc.bounces.google.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) (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 4Wd9Zx40LPz2yvh for ; Tue, 6 Aug 2024 08:09:27 +1000 (AEST) Received: by mail-pf1-x44a.google.com with SMTP id d2e1a72fcca58-70d188c9cabso9334568b3a.0 for ; Mon, 05 Aug 2024 15:09:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722895763; x=1723500563; 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=C2PiU8MTrEuvmn4oJRZEcNoPreaY/lLc5L+V0JuLroE=; b=xCEcxFHWNJJ2ItSdwQJiNlucsIyB7FQgsRcmphx3JMyIvSFbG8yeJHVaz8QIkydG8T dvFGNCTC62yytKJ0eVu8IBnFDmBycVqTtu9C5cthdWH2CzHI3JEs2zTi54EQoWqLTyIO CzIhMcnxus3g1nFI68hpMOMNASU6G+Gf7F9NgpuWwEArXdzKLjQF5g3++m0LMOtXfowm UQM3qJZBT5CAkzkggfkg4MN545sU9/HwxRTj4VgXizLxkloIs9H1agrWv2rwVND7rzjG ljS4bysj/Wc9JymMd/4XYf9CRcoChvtrrGTBLZ8A6SPjOXvbpu59TduLiyf7Lgy75e4m EzRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722895763; x=1723500563; 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=C2PiU8MTrEuvmn4oJRZEcNoPreaY/lLc5L+V0JuLroE=; b=RMfCKGk1Gct1534RYyVgGFjh31DFHHSqeh4VVT7slFyjq159VR9OV7gqGelRXVE45G sKy42B0NxMy+ZU4YxXgT8ZiOlf5ELMMq2RhyvX+PUDf+iQdvSBxB78M6H9mTcn8HRy/9 yAIjqdoc4jD9Le07NFcokCfAoy2rlnjI0zMt7A8Vef+EzFDilPNdVCO/UelCw449F0oh QiNjKLntXnThnIYYCl2ZX/v86HU8nlD68gpX1PN5Zw1ETHAfe+8gUI75Zb0OKalSZVfi 407ofcrOIwmWf5fR3wTFUILVsxSQYtC6rsgbVis6OvseIM4dXoGH6OyrTOji+Z8DGwuL BuuQ== X-Forwarded-Encrypted: i=1; AJvYcCV4rXamATX9J7h4eUaVbkAvR/9VmRT0rg9nu1t8QgHy/ySVc3G4H9KtaLGKfXZuViEF/1acEZ7Ooaqs+TtJDtprbJhVaN1OgfzNYGfpoQ== X-Gm-Message-State: AOJu0Yx1KhlxvBuYff99qs+5tTzxAcN8JyKVesmGg11c2gqsadUMU9V+ 0v3bLtqrCEpBXvqP2lNSF8SmZsXVQGIvbbVI63hKWRwqAoMbY4YGTVPa/wKw5CqXlnKubSfTmeh mwg== X-Google-Smtp-Source: AGHT+IFHGqnQ2aZELEsNF/YUFUu/OdaSqANvJ2o5+KNT08fnEczrxRkzi5g08NacDnyiiIzp3YSr6oxKzK4= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:6f0e:b0:710:4d08:e41f with SMTP id d2e1a72fcca58-7106d08296emr87588b3a.4.1722895762937; Mon, 05 Aug 2024 15:09:22 -0700 (PDT) Date: Mon, 5 Aug 2024 15:09:21 -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 Mon, Aug 05, 2024, Aneesh Kumar K.V wrote: > Sean Christopherson writes: > > > 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. > > What I meant was, should we consider mte_copy_tags_from_user() as one > that update the page contents (even though it is updating tags) and > use kvm_follow_pfn() with kfp->pin = 1 instead? Yes, that's my understanding as well. However, this series is already ludicruosly long, and I don't have the ability to test the affected code, so rather than blindly churn more arch code, I opted to add a FIXME in patch 76 instead. https://lore.kernel.org/all/20240726235234.228822-76-seanjc@google.com