From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C9ACC07E99 for ; Mon, 5 Jul 2021 10:46:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 29DAF6145D for ; Mon, 5 Jul 2021 10:46:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231187AbhGEKtT (ORCPT ); Mon, 5 Jul 2021 06:49:19 -0400 Received: from forward1-smtp.messagingengine.com ([66.111.4.223]:46395 "EHLO forward1-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230168AbhGEKtS (ORCPT ); Mon, 5 Jul 2021 06:49:18 -0400 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailforward.nyi.internal (Postfix) with ESMTP id E978E19407AA; Mon, 5 Jul 2021 06:46:40 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Mon, 05 Jul 2021 06:46:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=r7DAGOVAb7zSSo0L+ d/P8FgYd74M6jRPN2RgWh8KYPk=; b=KgMWzWdIBJOIpGP7IwiHnvjU6pdtsRVum Ly8bCEJsiwcLglbNmAD2sIppgnF4PxPjfEJhnHiz3GxPVmD0mdY5KsTK6nsUJVwG T6idON9LZESnIlJXosdI8LYJEyfzzpudtgCKWlSBoXOhQKIk8g8Rp3DwnxfpF9v4 r6h/5Ea3JN6rIsjq8jmlll2EeMUFwudqFOW3im42t+a7XCcwsTYf1nVKi24ymakd 2eNsRQX0Rjn8K8YSC22rbVqxwcBwQgVzNNlOhw4xzYkKnh5/tfKBn+ipkZTrOvp5 BQGL96Z5X3cd5w/YGV0u7eHDzuNcN0yqVfrNPrel/1H+6oHlhPoVA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfeejgedgfedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffoggfgsedtkeertdertddtnecuhfhrohhmpeffrghvihguucfg ughmohhnughsohhnuceouggrvhhiugdrvggumhhonhgushhonhesohhrrggtlhgvrdgtoh hmqeenucggtffrrghtthgvrhhnpefhfedtieevleetueeukeffvdfffeeigfdtvdffgeei tdegfeffleeihfevtdekfeenucffohhmrghinhepkhgvrhhnvghlrdhorhhgnecuvehluh hsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepuggrvhhiugdrvggu mhhonhgushhonhesohhrrggtlhgvrdgtohhm X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 5 Jul 2021 06:46:33 -0400 (EDT) Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id 18d5600b; Mon, 5 Jul 2021 10:46:32 +0000 (UTC) From: David Edmondson To: qemu-devel@nongnu.org Cc: Richard Henderson , Michael Roth , kvm@vger.kernel.org, Roman Bolshakov , Paolo Bonzini , Marcelo Tosatti , babu.moger@amd.com, Cameron Esfahani , Eduardo Habkost , David Edmondson Subject: [RFC PATCH 0/8] Derive XSAVE state component offsets from CPUID leaf 0xd where possible Date: Mon, 5 Jul 2021 11:46:24 +0100 Message-Id: <20210705104632.2902400-1-david.edmondson@oracle.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The offset of XSAVE state components within the XSAVE state area is currently hard-coded via reference to the X86XSaveArea structure. This structure is accurate for Intel systems at the time of writing, but incorrect for newer AMD systems, as the state component for protection keys is located differently (offset 0x980 rather than offset 0xa80). For KVM and HVF, replace the hard-coding of the state component offsets with data derived from CPUID leaf 0xd information. TCG still uses the X86XSaveArea structure, as there is no underlying CPU to use in determining appropriate values. This is a replacement for the changes in https://lore.kernel.org/r/20210520145647.3483809-1-david.edmondson@oracle.com, which simply modifed the hard-coded offsets for AMD systems. Testing on HVF is minimal (it builds and, by observation, the XSAVE state component offsets reported to a running VM are accurate on an older Intel system). David Edmondson (8): target/i386: Declare constants for XSAVE offsets target/i386: Consolidate the X86XSaveArea offset checks target/i386: Clarify the padding requirements of X86XSaveArea target/i386: Pass buffer and length to XSAVE helper target/i386: Make x86_ext_save_areas visible outside cpu.c target/i386: Observe XSAVE state area offsets target/i386: Populate x86_ext_save_areas offsets using cpuid where possible target/i386: Move X86XSaveArea into TCG target/i386/cpu.c | 18 +-- target/i386/cpu.h | 41 ++---- target/i386/hvf/hvf-cpu.c | 34 +++++ target/i386/hvf/hvf.c | 3 +- target/i386/hvf/x86hvf.c | 19 ++- target/i386/kvm/kvm-cpu.c | 36 +++++ target/i386/kvm/kvm.c | 52 +------ target/i386/tcg/fpu_helper.c | 1 + target/i386/tcg/tcg-cpu.c | 20 +++ target/i386/tcg/tcg-cpu.h | 57 ++++++++ target/i386/xsave_helper.c | 267 ++++++++++++++++++++++++++--------- 11 files changed, 381 insertions(+), 167 deletions(-) -- 2.30.2 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90C6BC07E9C for ; Mon, 5 Jul 2021 10:48:09 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (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 48D586145D for ; Mon, 5 Jul 2021 10:48:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 48D586145D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:40996 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0M92-00067v-9w for qemu-devel@archiver.kernel.org; Mon, 05 Jul 2021 06:48:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47672) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0M7j-0003Rk-EP for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:46:47 -0400 Received: from forward1-smtp.messagingengine.com ([66.111.4.223]:48125) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0M7g-0000Bx-HD for qemu-devel@nongnu.org; Mon, 05 Jul 2021 06:46:47 -0400 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailforward.nyi.internal (Postfix) with ESMTP id E978E19407AA; Mon, 5 Jul 2021 06:46:40 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Mon, 05 Jul 2021 06:46:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=r7DAGOVAb7zSSo0L+ d/P8FgYd74M6jRPN2RgWh8KYPk=; b=KgMWzWdIBJOIpGP7IwiHnvjU6pdtsRVum Ly8bCEJsiwcLglbNmAD2sIppgnF4PxPjfEJhnHiz3GxPVmD0mdY5KsTK6nsUJVwG T6idON9LZESnIlJXosdI8LYJEyfzzpudtgCKWlSBoXOhQKIk8g8Rp3DwnxfpF9v4 r6h/5Ea3JN6rIsjq8jmlll2EeMUFwudqFOW3im42t+a7XCcwsTYf1nVKi24ymakd 2eNsRQX0Rjn8K8YSC22rbVqxwcBwQgVzNNlOhw4xzYkKnh5/tfKBn+ipkZTrOvp5 BQGL96Z5X3cd5w/YGV0u7eHDzuNcN0yqVfrNPrel/1H+6oHlhPoVA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfeejgedgfedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffoggfgsedtkeertdertddtnecuhfhrohhmpeffrghvihguucfg ughmohhnughsohhnuceouggrvhhiugdrvggumhhonhgushhonhesohhrrggtlhgvrdgtoh hmqeenucggtffrrghtthgvrhhnpefhfedtieevleetueeukeffvdfffeeigfdtvdffgeei tdegfeffleeihfevtdekfeenucffohhmrghinhepkhgvrhhnvghlrdhorhhgnecuvehluh hsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepuggrvhhiugdrvggu mhhonhgushhonhesohhrrggtlhgvrdgtohhm X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 5 Jul 2021 06:46:33 -0400 (EDT) Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id 18d5600b; Mon, 5 Jul 2021 10:46:32 +0000 (UTC) From: David Edmondson To: qemu-devel@nongnu.org Subject: [RFC PATCH 0/8] Derive XSAVE state component offsets from CPUID leaf 0xd where possible Date: Mon, 5 Jul 2021 11:46:24 +0100 Message-Id: <20210705104632.2902400-1-david.edmondson@oracle.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: softfail client-ip=66.111.4.223; envelope-from=david.edmondson@oracle.com; helo=forward1-smtp.messagingengine.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_SOFTFAIL=0.665, UNPARSEABLE_RELAY=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , kvm@vger.kernel.org, Michael Roth , Marcelo Tosatti , Richard Henderson , Cameron Esfahani , David Edmondson , babu.moger@amd.com, Roman Bolshakov , Paolo Bonzini Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The offset of XSAVE state components within the XSAVE state area is currently hard-coded via reference to the X86XSaveArea structure. This structure is accurate for Intel systems at the time of writing, but incorrect for newer AMD systems, as the state component for protection keys is located differently (offset 0x980 rather than offset 0xa80). For KVM and HVF, replace the hard-coding of the state component offsets with data derived from CPUID leaf 0xd information. TCG still uses the X86XSaveArea structure, as there is no underlying CPU to use in determining appropriate values. This is a replacement for the changes in https://lore.kernel.org/r/20210520145647.3483809-1-david.edmondson@oracle.com, which simply modifed the hard-coded offsets for AMD systems. Testing on HVF is minimal (it builds and, by observation, the XSAVE state component offsets reported to a running VM are accurate on an older Intel system). David Edmondson (8): target/i386: Declare constants for XSAVE offsets target/i386: Consolidate the X86XSaveArea offset checks target/i386: Clarify the padding requirements of X86XSaveArea target/i386: Pass buffer and length to XSAVE helper target/i386: Make x86_ext_save_areas visible outside cpu.c target/i386: Observe XSAVE state area offsets target/i386: Populate x86_ext_save_areas offsets using cpuid where possible target/i386: Move X86XSaveArea into TCG target/i386/cpu.c | 18 +-- target/i386/cpu.h | 41 ++---- target/i386/hvf/hvf-cpu.c | 34 +++++ target/i386/hvf/hvf.c | 3 +- target/i386/hvf/x86hvf.c | 19 ++- target/i386/kvm/kvm-cpu.c | 36 +++++ target/i386/kvm/kvm.c | 52 +------ target/i386/tcg/fpu_helper.c | 1 + target/i386/tcg/tcg-cpu.c | 20 +++ target/i386/tcg/tcg-cpu.h | 57 ++++++++ target/i386/xsave_helper.c | 267 ++++++++++++++++++++++++++--------- 11 files changed, 381 insertions(+), 167 deletions(-) -- 2.30.2