Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp555024pxb; Wed, 25 Aug 2021 09:19:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLmgyWCCb9yG36Hnp0aS54JD5Zo/2YwHsRBPK4lixrTEzlNDu0YVmrV2K+fq9+d4Yt/JSo X-Received: by 2002:a17:906:9241:: with SMTP id c1mr46835394ejx.125.1629908394163; Wed, 25 Aug 2021 09:19:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629908394; cv=none; d=google.com; s=arc-20160816; b=aZicq7eL7PwnSVaD3xHP3+imD9Byf6nDVAGCRlYQ7MEXxOWIxOoiFELA2qWDdZiD21 Jj4G2SUBQvSa5uQEFUq9bv8Spcd+gvwv6guA/CZjkJ1Iq39ZSyg7jjvoKM+d0+RAQ2He BRHn2+E7lLPSUWWH35966ca8CAqrXTKQrGsWvS1pYCasF4foZliGLENLYipEpWKlXAMl TVxOJAS5RygHDFPRGlsF2ZPd1lgN2QNOaC06YO87bBfGV2lbW7iV0nL+UMEamCcPTI0d SRNXZAHL2RaxifqVSI0XN2kk7o4FIV4Ka4sPcagU1eBfdWIvLij0sAJwWQ9kD/kmts6D 7oDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from; bh=qbpqzPrKRy+uo3gLdZ0As+as7zbpTQMArxVT4S+WmNM=; b=a8v/Ixy9tRjeRGJWGE4CVYseDoynUdNH5Y3OLsk7oKAtC4R6PmBDzZOoPXYj22K8TD XQNo51OwLwbYQMQYe2WJDD2nsGSyrVOlRplQEiEhuNpcLWUtn174opATcjej5AuWej+i 4RrfP8eVZglu8bHBZlrwptHyodpa/hhfP070uWKiPD0DIDcXj7PM/TS1CTzm4rTH4zUF tuFRFz34SgVqWHK9h2OYQPKyeHZp389nZdTN8MGGP//xNCdPHnVcnrbiaZHm5aDbgyoW Qj4bi2y6mXBhwPLrognaZ8DHPhopIlRGeAwGgVFnHtDh8g5DP7929SFjnM19jDvRMOcl RJ/Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z8si461125edd.224.2021.08.25.09.19.26; Wed, 25 Aug 2021 09:19:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240473AbhHYQSa (ORCPT + 99 others); Wed, 25 Aug 2021 12:18:30 -0400 Received: from foss.arm.com ([217.140.110.172]:54720 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240303AbhHYQSO (ORCPT ); Wed, 25 Aug 2021 12:18:14 -0400 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 3F9F7101E; Wed, 25 Aug 2021 09:17:28 -0700 (PDT) Received: from monolith.cable.virginm.net (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E222B3F66F; Wed, 25 Aug 2021 09:17:26 -0700 (PDT) From: Alexandru Elisei To: maz@kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, will@kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v4 10/39] KVM: arm64: Print a warning for unexpected faults on locked memslots Date: Wed, 25 Aug 2021 17:17:46 +0100 Message-Id: <20210825161815.266051-11-alexandru.elisei@arm.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210825161815.266051-1-alexandru.elisei@arm.com> References: <20210825161815.266051-1-alexandru.elisei@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When userspace unmaps a VMA backing a memslot, the corresponding stage 2 address range gets unmapped via the MMU notifiers. This makes it possible to get stage 2 faults on a locked memslot, which might not be what userspace wants because the purpose of locking a memslot is to avoid stage 2 faults in the first place. Addresses being unmapped from stage 2 can happen from other reasons too, like bugs in the implementation of the lock memslot API, however unlikely that might seem. Let's try to make debugging easier by printing a warning when this happens. Signed-off-by: Alexandru Elisei --- arch/arm64/kvm/mmu.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 3ab8eba808ae..d66d89c18045 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1298,6 +1298,27 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) /* Userspace should not be able to register out-of-bounds IPAs */ VM_BUG_ON(fault_ipa >= kvm_phys_size(vcpu->kvm)); + if (memslot_is_locked(memslot)) { + const char *fault_type_str; + + if (kvm_vcpu_trap_is_exec_fault(vcpu)) + goto handle_fault; + + if (fault_status == FSC_ACCESS) + fault_type_str = "access"; + else if (write_fault && (memslot->arch.flags & KVM_MEMSLOT_LOCK_WRITE)) + fault_type_str = "write"; + else if (!write_fault) + fault_type_str = "read"; + else + goto handle_fault; + + kvm_warn_ratelimited("Unexpected L2 %s fault on locked memslot %d: IPA=%#llx, ESR_EL2=%#08x]\n", + fault_type_str, memslot->id, fault_ipa, + kvm_vcpu_get_esr(vcpu)); + } + +handle_fault: if (fault_status == FSC_ACCESS) { handle_access_fault(vcpu, fault_ipa); ret = 1; -- 2.33.0