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 5A250C3F6B0 for ; Wed, 24 Aug 2022 15:01: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: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=OgC77r8yoqW2Usl9vyyNsUBoPSCoeh9huhkt15W5Pew=; b=W1PiueXXM3Vshs Iws7QFmZTgkUhuoNKXadXJ9Qu4e+GEn4pQMyh3wJUcJprC3FhsDIK5AlTGNaM1DuJ+Sesim0pbEGi 1pcz2KbmsU06qIoZ1J4GM/JLXWmzEpQu697aHvuvZDJ5b05HNewBGnIwlaRrL7c9+PJ6rzZMpffMT FMQw9qTDZB7Lm66BfH02HcJbS+haq0HEI0UQeZKC8l/tlWBvkmcXlroNdyZ0EQCj5OxhrK41WXPDZ NaHDIkatdUsN/oARO1z3hWsAeSqrIirfovJgbwsh5vAXTG6JFTswmA+uB/g50DVrFj9e4J+CB1UOS aIgqfLIA54smhqSfccbg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oQrs9-00DqqW-3o; Wed, 24 Aug 2022 15:00:49 +0000 Received: from out2.migadu.com ([188.165.223.204]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oQrrw-00Dqjk-7l; Wed, 24 Aug 2022 15:00:38 +0000 Date: Wed, 24 Aug 2022 10:00:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1661353229; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=wpdpInv50s3/tIr2zAWlDOu11BVdoLVMcL8Ge4aE150=; b=vCNG6VW0yVkpK30QQEGBHc0IONpr09WwKoJRzM318XHzyPpdYjdo72Wro1vDzdAr0MYNLs EYH9TmimgWflNvzHC80WrzVMIezIPbQfNXq8NkEMiF6hjZuJQrG4iKwHF5FaWtL6Sovhst w05T8HvT2UqbKDR9ZLtxGz/iI8pVsbI= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Sean Christopherson Cc: Paolo Bonzini , Marc Zyngier , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Nathan Chancellor , Nick Desaulniers , James Morse , Alexandru Elisei , Suzuki K Poulose , Atish Patra , David Hildenbrand , Tom Rix , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, llvm@lists.linux.dev, linux-kernel@vger.kernel.org, Colton Lewis , Peter Gonda , Andrew Jones Subject: Re: [PATCH v4 5/6] KVM: selftests: Make arm64's MMIO ucall multi-VM friendly Message-ID: References: <20220824032115.3563686-1-seanjc@google.com> <20220824032115.3563686-6-seanjc@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220824032115.3563686-6-seanjc@google.com> X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220824_080037_484645_E880B4DC X-CRM114-Status: GOOD ( 22.46 ) 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 Hi Sean, On Wed, Aug 24, 2022 at 03:21:14AM +0000, Sean Christopherson wrote: > Fix a mostly-theoretical bug where ARM's ucall MMIO setup could result in > different VMs stomping on each other by cloberring the global pointer. > > Fix the most obvious issue by saving the MMIO gpa into the VM. > > A more subtle bug is that creating VMs in parallel (on multiple tasks) > could result in a VM using the wrong address. Synchronizing a global to > a guest effectively snapshots the value on a per-VM basis, i.e. the > "global" is already prepped to work with multiple VMs, but setting the > global in the host and copying it to the guest needs to happen atomically. > To fix that bug, add atomic_sync_global_pointer_to_guest() to sync > "global" pointers that hold per-VM values, i.e. technically need to be > handled in a thread-safe manner. > > Signed-off-by: Sean Christopherson > --- > .../selftests/kvm/include/kvm_util_base.h | 16 +++++++++++++++ > .../testing/selftests/kvm/lib/aarch64/ucall.c | 20 ++++++++++++++----- > 2 files changed, 31 insertions(+), 5 deletions(-) > > diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h > index 24fde97f6121..9ec7fbe941aa 100644 > --- a/tools/testing/selftests/kvm/include/kvm_util_base.h > +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h > @@ -16,6 +16,7 @@ > #include > #include "linux/rbtree.h" > > +#include > > #include > > @@ -81,6 +82,7 @@ struct kvm_vm { > struct sparsebit *vpages_mapped; > bool has_irqchip; > bool pgd_created; > + vm_paddr_t ucall_mmio_addr; > vm_paddr_t pgd; > vm_vaddr_t gdt; > vm_vaddr_t tss; > @@ -714,6 +716,20 @@ kvm_userspace_memory_region_find(struct kvm_vm *vm, uint64_t start, > memcpy(&(g), _p, sizeof(g)); \ > }) > > +/* > + * Sync a global pointer to the guest that has a per-VM value, in which case > + * writes to the host copy of the "global" must be serialized (in case a test > + * is being truly crazy and spawning multiple VMs concurrently). > + */ Do we even care about writes to the host's copy of the global pointer? I don't see how the host pointer is used beyond serializing writes into a guest. IOW, it looks as though we could skip the whole global illusion altogether and write straight into guest memory. -- Thanks, Oliver _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv