Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp72310rdb; Wed, 14 Feb 2024 13:06:38 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU+eSiOHLjGiqM2Rq15q8JUh4WC6U8WvNsRXwe2fGwA+3C7Y7N8cGp6Np+NAsIowbi+bmBUQUs+nlHT7aPRlhq4DGBt34NuB1OrURLLqQ== X-Google-Smtp-Source: AGHT+IHvvfy9o/p3WOFG6IHlAOre0MZjbZripe2puOJxFEtfhIWIRcZKhWUFynmhTHUiT/HrsBZF X-Received: by 2002:a17:906:8d6:b0:a3d:404a:4bac with SMTP id o22-20020a17090608d600b00a3d404a4bacmr2353881eje.63.1707944797828; Wed, 14 Feb 2024 13:06:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707944797; cv=pass; d=google.com; s=arc-20160816; b=gpK7okInLxzdXyQI2dKPt8eohoyiR2ho3z7g7U2B3vjBdoVmNA1F/kQiylDLCn+O1K Qx5Z3iMbCvB8OZuJjvEKJFrbeJxUqSrVKTi33narn7+DpYAokFAVnkyuQZQ1125Jx+oJ CgXSFNU1HzQwLNpEPxjO4YeqHolC5b5ZrqzobaViBOyxqgkwTdC7qJS+KFet04X975gs z/2L95UXawCJM6WVtMTbEMom4b7Cr1D+1OCpYxHop7cbadePcjBlQgu4fib1RYV/0WYG rl4V2kMgYWH+H1I12znWGcF2RK1YYyEdysrIQbj4ecRf9ujH7r9IROpP9cWkIyQ/if02 EpuQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:dkim-signature:date; bh=uO6O9l/7u1FoWCDVNDPi12vidxMFWsbJFIEI+vbkcWI=; fh=El9jKcjBXNz1cOxUHUUTF5a69VmMbhvThUSdWONKAjU=; b=d9ryog4IGmQRGN8mMLI/lyQwjj2VdMKgxzaiJ+LETeQK4WFDQDRFd57lU13BiOyyk2 0lxtFX/FE0DIjXpxkNSgK2lzGGlJB/r3x1AFzkRgSaXxEocCT/7MRRiEZS15lM2N0Nrq 1w17WPN+dnNbWK8H+hPH2OJjB8xq09fcppeQDblHsRCh0fhh0YSG1qTc0ipmztdiPrN3 xIPtWucvwAUXASgY46oSm8x8pqsacKB4ZdmPEHzToYfA9cMFAk/LP5jK//E/q4WTspF7 Y0P2CnHw3qwr0dR0BwxylUXGcwiL6toEp3vwPgCE6XfJJxBewbfzEfO+y35MO+nGRTUC 2Lhw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Qfvu4z1g; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-65963-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65963-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev X-Forwarded-Encrypted: i=2; AJvYcCUoAtBfRDA1h9HtDU4BSCUA13MGYKQUtGZNZc4rArNCaOhUTu8b5EtLlZj/gUBj7XnVOJ+c6dOZMLBXjq8w5ckG3JwAeX5/abcnJa7DlQ== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id la9-20020a170906ad8900b00a3d2ecb8db0si1241921ejb.523.2024.02.14.13.06.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 13:06:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65963-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Qfvu4z1g; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-65963-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65963-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id B4EFC1F23D1A for ; Wed, 14 Feb 2024 21:06:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F0EAA13DBBF; Wed, 14 Feb 2024 21:06:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Qfvu4z1g" Received: from out-185.mta1.migadu.com (out-185.mta1.migadu.com [95.215.58.185]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 398D855E44 for ; Wed, 14 Feb 2024 21:06:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.185 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707944783; cv=none; b=Jh1dYm2YU6JeosZgJUKnUDSx3o+gsObKQrPCZe5OeB+xPEZ1r7Xi7dZFOKwTye1HukbkVGWQCHqOZMv+jCxAOuUwgSPoM1Z6tvUPDTXPaadH6VL7TKJRNdoYXW7T6TItK7kCv8CrOnJVciDDmvutRS/SCmltFZsB2LnRpaqulC0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707944783; c=relaxed/simple; bh=c+0UADNx4KkHHaeDm/qEDcDyoYmLg07y339g5RmUM14=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=JmLOqPdwp0JzfqQDvwCZl5h6Wv2VQLVFvdJ+XAtCeyOO0DdHNyylB/gFYvZ3o1cwgsxSF02HAZSN6jnIidDElFQiNdBQaioLPvk73zJmVQ9RrB29VRm8XVcAuVlV/TT3apE8E51zEXJd6fV3kkIkXMCim7yt185Re4wtO6dn0tU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Qfvu4z1g; arc=none smtp.client-ip=95.215.58.185 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Date: Wed, 14 Feb 2024 13:06:12 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1707944780; 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=uO6O9l/7u1FoWCDVNDPi12vidxMFWsbJFIEI+vbkcWI=; b=Qfvu4z1ghH0eYQfo4WtcCs4NQnZnhnvCd/kiESIbOVEsb4Pk2KCeGoA7CpjxaUK3cNiCp/ N2IyDNCKrNA+pQoYJQOq+41kBXGMbfNasmhZgR/nS1tiefS9VwosW55GVWHiB7mKM1HoQQ xT6DRaSpb0uF7ELaP9CtEQsQKIUfdHc= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Marc Zyngier Cc: kvmarm@lists.linux.dev, kvm@vger.kernel.org, James Morse , Suzuki K Poulose , Zenghui Yu , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 19/23] KVM: selftests: Add a minimal library for interacting with an ITS Message-ID: References: <20240213093250.3960069-1-oliver.upton@linux.dev> <20240213094114.3961683-1-oliver.upton@linux.dev> <86zfw33qae.wl-maz@kernel.org> <86v86q4xkf.wl-maz@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT On Wed, Feb 14, 2024 at 12:55:11PM -0800, Oliver Upton wrote: > On Wed, Feb 14, 2024 at 08:09:52PM +0000, Marc Zyngier wrote: > > > If the order of restore from userspace is CBASER, CWRITER, CREADR then > > > we **wind up replaying the entire command queue**. While insane, I'm > > > pretty sure it is legal for the guest to write garbage after the read > > > pointer has moved past a particular command index. > > > > > > Fsck!!! > > > > This is documented Documentation/virt/kvm/devices/arm-vgic-its.rst to > > some extent, and it is allowed for the guest to crap itself on behalf > > of userspace if the ordering isn't respected. > > Ah, fair, I missed the documentation here. If we require userspace to > write CTLR last then we _should_ be fine, but damn is this a tricky set > of expectations. > > > > So, how about we do this: > > > > > > - Provide a uaccess hook for CWRITER that changes the write-pointer > > > without processing any commands > > > > > > - Assert an invariant that at any time CWRITER or CREADR are read from > > > userspace that CREADR == CWRITER. Fail the ioctl and scream if that > > > isn't the case, so that way we never need to worry about processing > > > 'in-flight' commands at the destination. > > > > Are we guaranteed that we cannot ever see CWRITER != CREADR at VM > > dumping time? I'm not convinced that we cannot preempt the vcpu thread > > at the right spot, specially given that you can have an arbitrary > > large batch of commands to execute. > > > > Just add a page-fault to the mix, and a signal pending. Pronto, you > > see a guest exit and you should be able to start dumping things > > without the ITS having processed much. I haven't tried, but that > > doesn't seem totally unlikely. > > Well, we would need to run all userspace reads and writes through the > cmd_lock in this case, which is what we already do for the CREADR > uaccess hook. To me the 'racy' queue accessors only make sense for guest > accesses, since the driver is expecting to poll for completion in that > case. My proposed invariant cannot be maintained, of course, since userspace can do whatever it pleases on the cmdq pointers. > Otherwise we decide the existing rules for restoring the ITS are fine > and I get to keep my funky driver :) > > -- > Thanks, > Oliver >