Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp10380rdb; Wed, 14 Feb 2024 11:02:45 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUxOu44tynsyzlRQ2y3dEIXc/FsFauRIxh346TAOdJ7i+g4f0dorIrPTRRyCaRDV8JAnR8RjNpRSBhFbv5vLyXdS856MuF/WMfS7H87Cg== X-Google-Smtp-Source: AGHT+IGI6XSGi/72RMq2NwspKGyPicxD0MMXh4pbtruVTmWaFqqmzvblP/9ZVoofSL+tQdzL4w09 X-Received: by 2002:a05:620a:2207:b0:787:2606:14e2 with SMTP id m7-20020a05620a220700b00787260614e2mr3164215qkh.42.1707937364892; Wed, 14 Feb 2024 11:02:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707937364; cv=pass; d=google.com; s=arc-20160816; b=ojhQEyWGRB9mSNuNhSf2xkjhN1cjpJd1q4wxdpatc4Zp4kDhVpEm+zD9XRNTrdV53b 6iC4XSoKlGiJMQtbNmacGRDwAYH4JtzTRT50qjGYHISqP+Cn2VlC9kFCkURVGK0uKdLT 35zYBGZYMlXqO0ElJUOY+tS1dhpdjXyFNADJftviHMTR632CAs7cmzY0PUrLoLknuQp0 7N4jAZNqjQljpdQ5i8tALH356ZqhCggFO5N2ghzVXrqLV/OO2tSN+xMZSmjnybCd/pnd Fo1y3EhZXi5+HZUzcZeRUdcHXJ80+B4HV87LccKNbEvnv0SO9r0ChX5LdQGWJXQKaEVV I94g== 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=4P041HuvLQ7qtWSEmdckANvsaD0Z2miUICFdYufhm48=; fh=AOKt6+u+knIde+YwdBV/V+B47ELFuQlzbL9RrA07IH8=; b=YbQtLO+pT8YsoMXgcF5B8k6l+1bWMldfMK3kGbIW/PFkRn6PxfhltPoZ8HKnZV8xnR 9J1D6EYW94u4vLrHafEzr/dPTL3rIeASGM1H94jgqIgGaz/TPTu7E9Wqj1mXU7EumNtH 60tR+6zUP994ClaIuvR57jVPl9TtdU59fivilxC7AS9n4WxdctwEMDo7j0+FggJhukLI lDlA4qyqz0UH44sVJioNR0YWEWiDll6JZzESwmmggcvpklhDFlRRdEGmOgEBhUWokIN0 H4x0sX0vtyZpB5UDhdVwGJR12IJyCQuHtEUXRg2o9HPuXnvS3qMNYukFALPOlaIAj3lP 0f3Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="X/1nET5W"; 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-65854-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65854-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; AJvYcCU650rDFDa1OlzmPWZSJFMWs5aLNaqOYjhAwezOwW/kW6yWc0LRA3cYFyc1Mj3RzHGNar9cd43YRMD8x7/KXUdqbjSa1BAnOqgcHBE2Sg== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id s8-20020a05620a29c800b00787196ecd3fsi5634401qkp.281.2024.02.14.11.02.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 11:02:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65854-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="X/1nET5W"; 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-65854-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65854-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 9D0C11C273FD for ; Wed, 14 Feb 2024 19:00:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B3DBE13A86D; Wed, 14 Feb 2024 19:00:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="X/1nET5W" Received: from out-171.mta0.migadu.com (out-171.mta0.migadu.com [91.218.175.171]) (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 4178913A264 for ; Wed, 14 Feb 2024 19:00:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707937209; cv=none; b=YIVeJcyzB1jbJX2mlu6L0Ngg6jscSXJ54F+FjHFLfxWDf5FbQft4R92SSft0Hk8Azi1kFze2MxzuuqzHai8js4+ZFEFHFFKtdxdvU5zhc7PQkYoM88NhBfRh2jwfI+U/CojaUx2XY3JxLo9XAANiENbWrWANN55R1uqr21zt23w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707937209; c=relaxed/simple; bh=UjVHdWRKxR1wWlwd6TPzyXgOHZ46hNGBZS4G23VAcsg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Uk+WSiPAwfkoTo0qzVrzAUCSSCWggVdRtwot0Cmlkw3Fj1A8reckTX1l+xURLEFJoE0nW2JWDlsM5vEOBU2FqWgBoEDVkeIgxbVCV6ey0eikjgqjoQbbrtyZ9MO2MxT8hSLKc96XQ2/vfk5KaYlJyCY9VWjoCDto7RK2vkW6E6M= 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=X/1nET5W; arc=none smtp.client-ip=91.218.175.171 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 11:00:00 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1707937206; 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=4P041HuvLQ7qtWSEmdckANvsaD0Z2miUICFdYufhm48=; b=X/1nET5WtPtVfcZtVet1QEGDzDL7K064t5P+ZUnZ8xbF7EWyqkGtFsTHy1iBUXEx21LNXr SqhzO+L68HlVXmUP4J6fLej7uI3fLYtv63jfC9iKchwWjhLfOJbDkVRt2A67PT8ZGO5MDB 2B37z9Zrxg8evl211A+GeQGjgfQUc2g= 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> 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: <86zfw33qae.wl-maz@kernel.org> X-Migadu-Flow: FLOW_OUT On Wed, Feb 14, 2024 at 05:32:25PM +0000, Marc Zyngier wrote: > On Tue, 13 Feb 2024 09:41:14 +0000, > Oliver Upton wrote: > > > > A prerequisite of testing LPI injection performance is of course > > instantiating an ITS for the guest. Add a small library for creating an > > ITS and interacting with it *from userspace*. > > > > Yep, you read that right. KVM unintentionally allows userspace to send > > commands to the virtual ITS via the command queue. Besides adding test > > coverage for an elusive UAPI, interacting with the ITS in userspace > > simplifies the handling of commands that need to allocate memory, like a > > MAPD command with an ITT. > > I don't mean to derail the party, but I really think we should plug > this hole. Either that, or we make it an official interface for state > restore. And don't we all love to have multiple interfaces to do the > same thing? Ok, I've thought about it a bit more and I'm fully convinced we need to shut the door on this stupidity. We expect CREADR == CWRITER at the time userspace saves the ITS registers, but we have a *hideous* ordering issue on the restore path. 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!!! 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. -- Thanks, Oliver