From patchwork Wed Jan 8 13:43:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 11323719 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0359313A0 for ; Wed, 8 Jan 2020 13:43:40 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id D5789206DB for ; Wed, 8 Jan 2020 13:43:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="aJI8VqK6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D5789206DB Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=pxNRu2UDt5C7P6zTFhwtaO3QdDaWdDkr9QcrFDJ+RJ4=; b=aJI 8VqK69f6HDWAQdYGKsnwBprmysh/hFYhhnatSFgcGLZ11Q8leRLj3+DyvAT6RTpNOeRTyGR999F4u d3vtKFttFw16qDhXcZH1KauH9LFreq6xEHQp8dXgjYfI5bnZ1AdsjX129UpYhEXKmv3LwyFiYLH2c BvB+y30t9swsFOCg+KFhnJdYKYjSt33CfPoYr2hMWPcCERuicrwgYDARFztasRe69UCCsDdAHc3M7 LsxeOA4XIL1/Tw3hKs9403qku4/bP4olnR3hMD2yCJzLn8bV3d3h4PF/9GTXF11w80fi4aD+9HsRD ZmUdO4UN8ovddD+S0a0MCD3gaXetnsg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ipBcY-0005yE-Sv; Wed, 08 Jan 2020 13:43:38 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ipBcW-0005xf-2o for linux-arm-kernel@lists.infradead.org; Wed, 08 Jan 2020 13:43:37 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D0DBC31B; Wed, 8 Jan 2020 05:43:34 -0800 (PST) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 4A7833F703; Wed, 8 Jan 2020 05:43:33 -0800 (PST) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, maz@kernel.org, alexandru.elisei@arm.com Subject: [PATCHv2 0/3] KVM: arm/arm64: exception injection fixes Date: Wed, 8 Jan 2020 13:43:21 +0000 Message-Id: <20200108134324.46500-1-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200108_054336_164049_5D65463B X-CRM114-Status: GOOD ( 10.59 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [217.140.110.172 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, peter.maydell@linaro.org, drjones@redhat.com, suzuki.poulose@arm.com, stable@vger.kernel.org, james.morse@arm.com, will@kernel.org, julien.thierry.kdev@gmail.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Hi, While looking at the KVM code, I realised that our exception injection handling isn't quite right, as it generates the target PSTATE/CPSR from scratch, and doesn't handle all bits which need to be (conditionally) cleared or set upon taking an exception. The first two patches address this for injecting exceptions into AArch64 and AArch32 contexts respectively. I've tried to organise the code so that it can easily be audited against the ARM ARM, and/or extended in future if/when new bits are added to the SPSRs. While writing the AArch32 portion I also realised that on an AArch64 host we don't correctly synthesize the SPSR_{abt,und} seen by the guest, as we copy the value of SPSR_EL2, and the layouts of those SPSRs differ. The third patch addresses this by explicitly moving bits into the SPSR_{abt,und} layout. I'd appreciate any testing people could offer, especially for AArch32 guests and/or AArch32 hosts, which I'm currently ill equipped to test. Ideally we'd have some unit tests for this. These issues don't seem to upset contemporary guests, but they do mean that KVM isn't providing an architecturally compliant environment in all cases, which is liable to cause issues in future. Given that, and that the patches are fairly self-contained, I've marked all three patches for stable. All three patches can be found on my kvm/exception-state branch [1]. Since v1 [2]: * Fix host_spsr_to_spsr32() bit preservation * Fix SPAN polarity; tested with a modified arm64 guest * Fix DIT preservation on 32-bit hosts * Add Alex's Reviewed-by to patch 3 Thanks, Mark. [1] https://git.kernel.org/pub/scm/linux/kernel/git/mark/linux.git/log/?h=kvm/exception-state Mark Rutland (3): KVM: arm64: correct PSTATE on exception entry KVM: arm/arm64: correct CPSR on exception entry KVM: arm/arm64: correct AArch32 SPSR on exception entry arch/arm/include/asm/kvm_emulate.h | 17 +++++ arch/arm64/include/asm/kvm_emulate.h | 32 ++++++++++ arch/arm64/include/asm/ptrace.h | 1 + arch/arm64/include/uapi/asm/ptrace.h | 1 + arch/arm64/kvm/inject_fault.c | 70 +++++++++++++++++++-- virt/kvm/arm/aarch32.c | 117 +++++++++++++++++++++++++++++++---- 6 files changed, 220 insertions(+), 18 deletions(-)