From patchwork Fri Aug 2 15:16:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 13751629 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 B4D2515C14B for ; Fri, 2 Aug 2024 15:16:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722611782; cv=none; b=dIp2IaN9tG5BMBi8zXCzctE3uIoGyq9R4HIak96kCe3jPtuxDKkuGLd4Su3IJCwFJfSRU3sO4koTiO8MW8oVHAsXFLvhiIOjr+OZaoQ0VLbxYJ6vO+GtIka+OPtF8RmrmTLIvjWNf2NUDmoCvmY1W48IZ3KmGVNHRsQ6nwFkHYI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722611782; c=relaxed/simple; bh=iuimfJknKx17ZsRwE8HxkPVR9wtDKQz5UqYPwUcW5+E=; h=From:To:Cc:Subject:Date:Message-Id:Content-Type:MIME-Version; b=L8I8WLtqwxYr7CpIQSd/Dt4DjFUk1aTHW/atFiq8xrJP6VyIzgOf4axurM4n7v0XzzN14Ee2J08Zt9JJJZPzlxOescOR98h8aS6xl2RCgWuuNmrdEoWqUG2sINZj73sJ4UxgCEVoxLsfoyyFFGrFuj6r+mx7iTkfzgzJBMno9iA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=jFintkjt; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="jFintkjt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1722611779; 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: content-transfer-encoding:content-transfer-encoding; bh=dB8ZjsQi0DqhQ19QW4eHSso4LuqSpVC05OgWx9LUJeU=; b=jFintkjth0O+AKuylQy1hOpKfsuzIS8DpPnH1yQtjNPJ7YjhBy3b4xO0gqcOfKF/mVXxIr HYOZt+nJQkwYWmZrXhBLyT0OeEMY5oj29lrAhNBR/RS/oR/EuzULUfRxiXCzsq9FMXnDct x+R8gIjuUPtQkFwqn13opzei1CXuJ3A= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-626-sELmaxqFNACf-wJmQ0HHjw-1; Fri, 02 Aug 2024 11:16:16 -0400 X-MC-Unique: sELmaxqFNACf-wJmQ0HHjw-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6DDED195421F; Fri, 2 Aug 2024 15:16:14 +0000 (UTC) Received: from intellaptop.redhat.com (unknown [10.47.238.37]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EE2481955E80; Fri, 2 Aug 2024 15:16:09 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Sean Christopherson , linux-kernel@vger.kernel.org, Borislav Petkov , "H. Peter Anvin" , Paolo Bonzini , Ingo Molnar , x86@kernel.org, Thomas Gleixner , Dave Hansen , Maxim Levitsky Subject: [PATCH v2 0/2] Relax canonical checks on some arch msrs Date: Fri, 2 Aug 2024 18:16:06 +0300 Message-Id: <20240802151608.72896-1-mlevitsk@redhat.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Recently we came up upon a failure where likely the guest writes 0xff4547ceb1600000 to MSR_KERNEL_GS_BASE and later on, qemu sets this value via KVM_PUT_MSRS, and is rejected by the kernel, likely due to not being canonical in 4 level paging. I did some reverse engineering and to my surprise I found out that both Intel and AMD have very loose checks in regard to non canonical addresses written to this and several other msrs, when the CPU supports 5 level paging. Patch #1 addresses this, making KVM tolerate this. Patch #2 is just a fix for a semi theoretical bug, found while trying to debug the issue. V2: addressed a very good feedback from Chao Gao. Thanks! Best regards, Maxim Levitsky Maxim Levitsky (2): KVM: x86: relax canonical check for some x86 architectural msrs KVM: SVM: fix emulation of msr reads/writes of MSR_FS_BASE and MSR_GS_BASE arch/x86/kvm/svm/svm.c | 12 ++++++++++++ arch/x86/kvm/x86.c | 11 ++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-)