Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp292698lqm; Tue, 30 Apr 2024 23:51:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXP/DJwNN7HEPa6q+Q2JW9beNIshyaw0ADJjcXMIuBjbGLO+iuPPt5ihyp/wmrA4S8BqrL8/PH4gKzOeeQ7SLnAbBbPooyA/yZTc/qaeA== X-Google-Smtp-Source: AGHT+IELuSH67+M9lEKnHqnmlmkEfiPUV2h6G5D+dcd01JZ8khxUmu2SdtLy1wqoVVXuE04vHYvJ X-Received: by 2002:a17:90a:9c1:b0:29b:c9ac:c563 with SMTP id 59-20020a17090a09c100b0029bc9acc563mr1550735pjo.19.1714546311687; Tue, 30 Apr 2024 23:51:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714546311; cv=pass; d=google.com; s=arc-20160816; b=0kU1K199jxAvFCD2yDfyCSVFRhb1mgBDRBfRtdsw7PMPfqnsWkmOLrfl5D6tJYW4AT AbdmY6dBUrkxQGaXFRLgkL2CIY5P0AcH/AVG2u1YhXwDzvdxUqGL7701cepSCCkJcLRP AqQV1cf85XcWZt6oaoS24b8x08+eKeYvbYmwhDJuU8Cu7XIjuzGD4vNLOkhSeYp/Yk7e /QkLrEGEifAKPLqHVvBiQpx81g6RrCuN7uMzv8bC9MsSNvrSLZa4XgYPNGnblzFrumAy ztE/AOoWILk6kCi5ibAkox+XBZfvoq77aqlfLPODT6vF+5yd/SwEzAe13wOrLgOtOmDg Ym/A== 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=CWi8bLLKtBukGh8G8zTTjC/3eWfwrHWDi/RHw99/oFY=; fh=dC6bgcv1LZxbrPgO2LLLE9/fKqigeIojCZwwV9paWH4=; b=IuqKKeQgPrN3cbA4zilZ12n6jgGRkte/tgdTbaoFLFU8HAj4XJ3492zwqibtSK5mS/ GxUiiyh+quX0eIMLJK9gU3ocMi1xl0MpRF9+JRQRVx1RYjsplOfmEI25yRiJFYV5Mf+T hw5bmMwLFQKzjKZ5YfVYwFn/detL0O+EhSE0vS0EhUzWXvJyq68601oS8uOneBIyFeiT 9FchBcPynGVrzoME5I0itA8sct6bPIEVMQcM7NV27f+yYr04LP/udhsnyrVKZRhY8vLN WTL9UAaRdWopV/XHj4+JzrJfehdQdNxYbjp8pS+yK2OC8eR/wAifBKJ1ffXZnouX2gsO Z2PQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Ai3adrx8; 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-164975-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-164975-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id gj5-20020a17090b108500b002abd9c77040si908358pjb.60.2024.04.30.23.51.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 23:51:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-164975-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Ai3adrx8; 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-164975-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-164975-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 130F5B221AC for ; Wed, 1 May 2024 06:51:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 91FFD4D584; Wed, 1 May 2024 06:51:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Ai3adrx8" Received: from out-171.mta1.migadu.com (out-171.mta1.migadu.com [95.215.58.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 9B9283A1AB for ; Wed, 1 May 2024 06:51:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714546280; cv=none; b=IeuJaO8oP04ZmpwVHG0dG1YL3MO/ooNK4Wr3ap5C7//jC7YC1+nnRppBPHaUqQAoNt0mT9XcP8YYtlyQvrdO4sEd9RO8FpMy0tNExIPPavhMy8duUgY2JDtz9BuoPywHXA5RFHGtbVptlTYQQWZDHt152TR3Bxw1Sn3Wxt3TfHw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714546280; c=relaxed/simple; bh=SireIWA+TEphRA7LVA2Cy7B/RDfmWBPVxRODIiZM74o=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=lPQ9niPh7vKVFfb86nOWoZA7vqsFN7S1gJarvOs2ACYYODvz55n+KSLr9nmWWwG4OpSZCUWPHa7DvBhWF+ZPIitA0ZWVyAO4tCCCTMcocmRo8B52qdSa7sMuXW7c8tgB8cmO+pAqhj1p1KRw3nTLnSGqrB7txH/h7x0qpZDUANI= 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=Ai3adrx8; arc=none smtp.client-ip=95.215.58.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, 1 May 2024 06:51:11 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1714546276; 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=CWi8bLLKtBukGh8G8zTTjC/3eWfwrHWDi/RHw99/oFY=; b=Ai3adrx8ClVvRwCA5urG/wBGSd0ZhpkPcliTI60FIvrx2jdMTcNTcAPxsu/H5gFxBmbKct WekqzR6yVfJLEqbAbu94jAWErnYXS1SV3YjuwOsusm1bkYZTEYOziCbwNY+whcWNh9JDRt P+Mfa/SaYLqy2nox9/YFZIiaU7wSGhg= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Sebastian Ott Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Marc Zyngier , James Morse , Suzuki K Poulose , Catalin Marinas , Will Deacon Subject: Re: [PATCH v2 2/6] KVM: arm64: unify trap setup code Message-ID: References: <20240426104950.7382-1-sebott@redhat.com> <20240426104950.7382-3-sebott@redhat.com> 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: <20240426104950.7382-3-sebott@redhat.com> X-Migadu-Flow: FLOW_OUT On Fri, Apr 26, 2024 at 12:49:46PM +0200, Sebastian Ott wrote: > There are 2 functions to set up traps via HCR_EL2: nitpick: these functions *calculate* the trap values, but do not actually set them up. HCR_EL2 doesn't get written to until further down the line on KVM_RUN. > + if (cpus_have_final_cap(ARM64_HAS_STAGE2_FWB)) { > + vcpu->arch.hcr_el2 |= HCR_FWB; > + } else { > + /* > + * For non-FWB CPUs, we trap VM ops (HCR_EL2.TVM) until M+C > + * get set in SCTLR_EL1 such that we can detect when the guest > + * MMU gets turned on and do the necessary cache maintenance > + * then. > + */ > + vcpu->arch.hcr_el2 |= HCR_TVM; > + } It seems to me like calling this once for the lifetime of a vCPU will break non-FWB behavior. Like the comment suggests, these traps are needed to catch the moment the S1 MMU is turned on and do cache maintenance to make sure D$ agrees with what the guest was doing before enabling the MMU. KVM_ARM_VCPU_INIT resets SCTLR_EL1, but it seems we'd miss setting HCR_TVM in that case. -- Thanks, Oliver