From patchwork Mon Sep 20 10:37:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Edmondson X-Patchwork-Id: 12505067 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=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,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 7C59DC433F5 for ; Mon, 20 Sep 2021 10:38:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 64081610F9 for ; Mon, 20 Sep 2021 10:38:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236058AbhITKkL (ORCPT ); Mon, 20 Sep 2021 06:40:11 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:29748 "EHLO mx0b-00069f02.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235917AbhITKkG (ORCPT ); Mon, 20 Sep 2021 06:40:06 -0400 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 18KA9Yoo019643; Mon, 20 Sep 2021 10:37:48 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=vkRPZ+VoJSi1c4vsO7PDtPst60HFkVEdoBfrAZpPA+U=; b=GQBi2jgaD4uPmtx5mCWZLLBbmFUPv6Sv9hG2Qwfti9sp3RngPDGVp8Ot1A6awv3vEXHm Dh+YmxczwKkvF2QBW3sv53zk0hPE2BSvaQ73/mYzDUX2ZRCVjNdhFeoWirId/oDon6sN T5v7TjTGx4zEuyVmJRqkgWcnmPo0ZDkfZf5/wPGqxMpZXCVYh5suycdkVNAmtL44FXLp z+JbcI4bRUBw0imefems2ogu/AaqwokB3EhShu14xcocowAirmNbWvBwUyiBa6f1bdRz 67j/RfkYgzXuNyFaaJcwEx1i4x/UXAdimQy2ZaaiqIlauCZDAofbsCcEav55WeF5wAVv LQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2020-01-29; bh=vkRPZ+VoJSi1c4vsO7PDtPst60HFkVEdoBfrAZpPA+U=; b=LbBidCnyqnAtCSm0leTPYRBVHbfV3kR6sps/GaWQmXEnhMohSw/9yzR6Svwfll2EeKFP Ojij5zemnruRXnOz/6/167GTjiDPN9p5NCYXR9H/gwavnoHwsXVlWMAJbf1OIdYYz9R6 yw6StgJucesdEWN1KzSe5ff3a5QVeQICBSaZeer/ydNjasSOTw11D2311yFZRNy9/GSw dTJhESWIfgNs9dDrRT69vOQpwYOWh1/Cvno6+VJMOEBPO/GkUleVCzh3O6nji+q42MXg 242A9ByU+jpZq0MIykACsP1SrOH+mA1ixcokyHYp11nz9AFa4/6tP1h3fIq17uKsKUzC gg== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3b66j2huxx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 20 Sep 2021 10:37:48 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 18KAVTOo106020; Mon, 20 Sep 2021 10:37:47 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2170.outbound.protection.outlook.com [104.47.55.170]) by userp3030.oracle.com with ESMTP id 3b557vbvc6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 20 Sep 2021 10:37:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YMbTz7stPlKosmXIaLhrn8+DPryYFznQ2Xd60mKKyMLO4rrJ2rwiyNJsUcO5E18KLyMAC7Sa6p4+B1H7CYeKWuCztDhurLw6+vWu0S7I3Q1e3YkhP0+xrhuDytwFLMDdcoi9eklcUEpU4U86oX6CidM0MOd0FPgHAWiz10t0H38VeKxUu1Gm2tlwyS5qfW9BLLDGPhqFwF3gQREI4W/C7+g6Xosd/kUO7WUMTCU6SNQJx2jwp5nfAI0UE2Ll4v7xWEVeYR3YSl4yx+dqYrwYmyJ/XfWiGpra8dDh1XH3SieFr0FKSf7eC4Cnshz3eC9+pwXceO87WqJg2u6cFufSdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=vkRPZ+VoJSi1c4vsO7PDtPst60HFkVEdoBfrAZpPA+U=; b=QLk5lNRDXmTznxdFyaOOq0OWEaZHf/TwRSP8HteIjUVKfP2f35lRyFZ5ItpxO2UJd0cTQlaCnqv0uGSwhR8DoBbmO0SxgjTKRH12EaBdGsWpbE1EwqvdyBp6nfRfWtrsRE11MHxy/QxWLlb2gRZWTB9oeHPfzEvRe9qdUa17mWxFGH22F1gK+XJ4R/vTcpZMIUhS5/ZjFWwoaLM9KT+gLh9HP6awLaWWXXR2ZKn/Gcz2NdxGqSvyWalNV95fu2P5a3H2Zf8E4q8sVeaHrnaGVYTJ0YacLqQa96QPHiflJY0shxxGBpoSVKVTD2mX2GBINp6R7IEHM3va1lVoa+ZQ2g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vkRPZ+VoJSi1c4vsO7PDtPst60HFkVEdoBfrAZpPA+U=; b=JDfIZ6RZGHgca8wfSxVHfz3TQa4PhfF4bPnlLhP620qZkqQ7fk4JPrW4ufyPcu8xwrVgAjXIx8ex0fJ7DGETyzGvwCfXOFf01Mgbb0N2fTx5jyqHXyBKmMAcGtDVs5B5KU+I6Pkra/GLkuIbIh14pjdDwYLT13NJBjB+X0XvtYs= Authentication-Results: google.com; dkim=none (message not signed) header.d=none;google.com; dmarc=none action=none header.from=oracle.com; Received: from DM6PR10MB3148.namprd10.prod.outlook.com (2603:10b6:5:1a4::21) by DM6PR10MB3308.namprd10.prod.outlook.com (2603:10b6:5:1ab::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14; Mon, 20 Sep 2021 10:37:45 +0000 Received: from DM6PR10MB3148.namprd10.prod.outlook.com ([fe80::6124:acae:c33e:1708]) by DM6PR10MB3148.namprd10.prod.outlook.com ([fe80::6124:acae:c33e:1708%6]) with mapi id 15.20.4523.018; Mon, 20 Sep 2021 10:37:45 +0000 From: David Edmondson To: linux-kernel@vger.kernel.org Cc: "H. Peter Anvin" , Vitaly Kuznetsov , x86@kernel.org, Joerg Roedel , Ingo Molnar , kvm@vger.kernel.org, Paolo Bonzini , Jim Mattson , Borislav Petkov , Sean Christopherson , Thomas Gleixner , Wanpeng Li , David Matlack , David Edmondson Subject: [PATCH v6 1/4] KVM: x86: Clarify the kvm_run.emulation_failure structure layout Date: Mon, 20 Sep 2021 11:37:34 +0100 Message-Id: <20210920103737.2696756-2-david.edmondson@oracle.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920103737.2696756-1-david.edmondson@oracle.com> References: <20210920103737.2696756-1-david.edmondson@oracle.com> X-ClientProxiedBy: LO2P265CA0036.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:61::24) To DM6PR10MB3148.namprd10.prod.outlook.com (2603:10b6:5:1a4::21) MIME-Version: 1.0 Received: from disaster-area.hh.sledj.net (2001:8b0:bb71:7140:64::1) by LO2P265CA0036.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:61::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.16 via Frontend Transport; Mon, 20 Sep 2021 10:37:43 +0000 Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id eb7d8700; Mon, 20 Sep 2021 10:37:38 +0000 (UTC) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b5d3e4e4-cfa3-4365-f528-08d97c22ae9d X-MS-TrafficTypeDiagnostic: DM6PR10MB3308: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3513; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Nv0ZN813c6igNWhpw0FDCAXYw1LBuJZrqLAJj97gaOweLZEX+JPR7fKPaZ4P+2X4DYhp7f05vGJJxFvYNjmc/f5XENkWXQet8XzJp62iCiN/27I2iaOxR/wVW15Fr1OYpuUOiCWqgNQkt/plOCUkjR+jPJJU31gOSmQdUNlJsXIxGzOcNMvFglhJc/+FlNFQ5ykFTticHs5cHiIfeylFKNAVNj+FbHcEIrs2tHpcVPr7rFoetgLZikDp1u4t1MhmFQhxbkRWiYCCLjgaT3+R7ZDguDYEDJqm2QgUB5df8Or649TZB4p+8B2miFb1YiEi5p6R9GHayIkT6u7jkf+yjflR5+vLKA2M4bL+FCmOkrdUl8j169hDWvWSLzT0w3ipqd40UHAFvDTLBED8krv7vd9jrZjmv/GDLt94+RgYG7Li1/jESQOXleqtOiV/Sf85v8HYSVOGZWIWNsf1KWfe7pNhJe2bll96ae0iwegsbZK5wx2c2UIo30AtEWT+oa4HuH3M/nATqH6ofCsbr+KSNFMAY0yMybIOIe9FN2LvMpUYcaiQukOSKzBtn6f4KvRSYBXqQHUGE9/45svwr6sv85J6BPK9YHlGUPWaXeJrv070vPEzu+JfI3dSsF9ZlBfwaBKODv8bLIXGXX4JeASm8g== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB3148.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(396003)(366004)(136003)(39860400002)(346002)(376002)(44832011)(36756003)(4744005)(107886003)(1076003)(8936002)(7416002)(8676002)(83380400001)(186003)(4326008)(52116002)(5660300002)(6916009)(66476007)(6666004)(66556008)(2906002)(2616005)(316002)(38100700002)(54906003)(86362001)(478600001)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: tva6jbtarSat3Evn5ihXmjSUaZO9fp1RGsBrnoOv0yX2nLmz9ZmQuT6zP06mCowKqmKF+l4oet1B+qW0iteT4LWCofW6ST1Ojezlu6OPleIPnxpuYgfReYONMbaJgz30nct1XngLmCcv4/eST7YteZGdjPpWfCMAT7eKyUOeYpNsW3+EpY6iQLbfXfahkOBFyvjd1/t4mq6jytGH7XFB8h41fy1hGY/FUnKZ8xsXP2raNHNvL+bQy5q27Eci7LITBar2j8ZITaC8teFDVUDYD7F0AmOi+9A3UV4fCLvhR77tD/mg4aM0X479BQrvGWIjUPSm73lhbVPPCz4xha5+cToS8R8bEQ5vWtVd3cYIjXbtP9379JodwL7Dg2Y4vnkkl3RYIPtWHy7R78FozVCVaviuZhCttVIPF8ZA+VAxbAgU7o68NtlJVE+IMB0bKFZql4oBo0lvmD8AarNMlTgHI05oXxvttHg0Jp0C8+GKy/E9GVpIbOSmOZ8h/Jcb5xX3PTsAdAzqR+NzDnIEEglqEm1GSXxN3cHUDQ3wvBCYcW24NoyZHWIVnPAcIyTaIocuq0g6TIRMRd8e3Y8LJ3ljeptUL+tVAK6M0q3XHxjEItFRXTP5YKxVEROAQ/3WiyXXFZT/MOEPjjlHnSOEl/xj8vyXIbgOk1so/i1277kTGoWra9wKIUzlrE25lU27v1p1vgn9IBanNd8GHvkyWtKPQhZGYI+yv2EebJ9mDB0MaV1X9g5DzGvvTFWpis3eARNaf7lnnKaI7ZJ/mNnBUj0nVxwkKUVXy0yBrlvhbt/+cZvr/QAgslmaaYjPYN7YSvz6mVfhrnotUvm/iLItT1tj4wGmdqnIOeG45z0r6QLfJmvAls0VL1QndrRjgUtNJ5mS6chsZSHGUKc5Yv49tYIeFKMu1o/59dSx1hYUL2o+SJw9UEdvwt4VKlmmwwsDA6cIiAL7wCnuT32sUboz4CNmgBvZtDKAm4aIJten3/0/K5eUFCH0+yVqedJ8b3/bvXQtuylcJ0Saaz5jC6izR+su2S+ImFiMYj74aUUfFhv3U8vCndmbE13D9XveFF9dorUGCCkpe1ruRvqCeSEaxPKUAcu1CxYvo4FIA1T8wLIIyQMsjxxpfA3nBOliS9YMJSVM2v2rSunEYYZbnJrUyxKmfz1+GWgjDbmwPAs/RzGCjgn0HPGK38uaU/4jdrBgAs38ZVT51lKBDIJ362i7rrZ0HTCH3nxppodedFbT+P37X19ObgCoISeMNkIi28iUdzcldN189T75RXJ1A2HUdBqmV13zHGd+gJAKkmmgx34JQWFUZ7eJ35oF/K5YriJLI/r0tDdtcY/kxexzKoASPS2JaQ== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b5d3e4e4-cfa3-4365-f528-08d97c22ae9d X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB3148.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2021 10:37:45.1594 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: r2ZOTKtonmGbopFPtTqXyLDcKnVabA60NhXDHImiH6tCLPNuHkcshrp1z3Lkh/MLcBp3CBGmOeShQiW+5j0WzR1RXsZQWy+LUIbR9FowLUs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR10MB3308 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10112 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 suspectscore=0 spamscore=0 bulkscore=0 adultscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109030001 definitions=main-2109200064 X-Proofpoint-GUID: 6M_vuqAIzk5wv0EaPZ9JDKpI8lco8zS9 X-Proofpoint-ORIG-GUID: 6M_vuqAIzk5wv0EaPZ9JDKpI8lco8zS9 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Until more flags for kvm_run.emulation_failure flags are defined, it is undetermined whether new payload elements corresponding to those flags will be additive or alternative. As a hint to userspace that an alternative is possible, wrap the current payload elements in a union. Suggested-by: Sean Christopherson Signed-off-by: David Edmondson Reviewed-by: Sean Christopherson --- include/uapi/linux/kvm.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index a067410ebea5..8618fe973215 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -402,8 +402,12 @@ struct kvm_run { __u32 suberror; __u32 ndata; __u64 flags; - __u8 insn_size; - __u8 insn_bytes[15]; + union { + struct { + __u8 insn_size; + __u8 insn_bytes[15]; + }; + }; } emulation_failure; /* KVM_EXIT_OSI */ struct { From patchwork Mon Sep 20 10:37:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Edmondson X-Patchwork-Id: 12505073 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=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,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 59549C433FE for ; Mon, 20 Sep 2021 10:39:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4319461107 for ; Mon, 20 Sep 2021 10:39:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235968AbhITKkZ (ORCPT ); Mon, 20 Sep 2021 06:40:25 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:44554 "EHLO mx0a-00069f02.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236113AbhITKkM (ORCPT ); Mon, 20 Sep 2021 06:40:12 -0400 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 18K9rDtD028205; Mon, 20 Sep 2021 10:37:50 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=AINhbha6E3GTdJOoRKH2ne8Q4O6aSfY/BRwpeJacKqo=; b=O9VQ6aMxGEwO6bqNjXltjSZRxs6JF1uceFnh6HjvJ46xcFRiDAK681ev9RcIIHZA+Nin 6RRJLk95leHeHo6KrCjZg5w0x+LxfWixbpcEJXtEV3SSrKd0V0Li5gZ/jerikpHAjaZk XIcrgPBmBSxvbH/4BpF1+tYbSewlE2nWBGVSlYZwsaaBp3u/BiqTxkVkbYp/Ornb49yt 7WPUFREMS9aXdFzOSCRll5dK+LCqeWNp05bFxxfSkEHG8WyPO8pjUkUSo7BDYAVkqTEz tgYdf2EQBg+BloDhl45aKSKOfjjlTTh5CZNhlRayIVvfHm9jos7XJaM2eyh8tvUXwlrz /Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2020-01-29; bh=AINhbha6E3GTdJOoRKH2ne8Q4O6aSfY/BRwpeJacKqo=; b=NsBxOy0mZspd5/EHmDVLbdwr/XsPtSOcNklqszT82tYg4010l1k62X8yBJ3lqv4z6IE1 19sR4WRxGud4jJ/0E8C3aTFDS0YcJHcsXC1hmia0xtxhm34k8byaQK0Wx01ViHqUpmMZ ZXGK5BdYHweN5w3NbtbtBDgyPjhdJyhExu4YGERSx1Kd7zlIeBAdA//Y99ny/JmobgQI GV04WeewUzUQulF5Z7IauvoEx+rzL0KRpcStc7ThZm/Ads6obcokj493m9INBZ2LzKUj kw4HFE0B5r13i745TkeP5+Kd7VaJ3Kn59kCUJTkvyGl3dcmS0ZlBZaJdALbAJ6TbEhga +A== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3b66wn1vs5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 20 Sep 2021 10:37:49 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 18KAVTOp106020; Mon, 20 Sep 2021 10:37:48 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2170.outbound.protection.outlook.com [104.47.55.170]) by userp3030.oracle.com with ESMTP id 3b557vbvc6-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 20 Sep 2021 10:37:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JoXOYRGudOh1mvSuEkQasBElgyMgW5eEYlZWFvOo31iXpAmiVC960B6kVcM+a2PLyHOGFN2kbvDHBS3IAcIEYOTJtvhCCwR6UpQOBbet6pLDsUrZBDPd4rgAAs3ITArDEoYSSBrQ+4xUWT5XS6zHcT/QVw41E3o9CZUuGPKJGkjtHrcyN4+pPI0rvB0BYUjnTa7D3pc+ds9PHY/5mLQVyVqyo5a2tkoAncycI3Hxl3OQBe7LsD/aenmFioqR1CyE/FwkpFywF8lO/4PMMxftryT7AZrtSU50TO7HvRdeeIgLxsqr+bMHUQtDNgrO2SVDGd27CtqicF0cMSi3e74acw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=AINhbha6E3GTdJOoRKH2ne8Q4O6aSfY/BRwpeJacKqo=; b=fQsqyn9YgNuWs1KfcT/UBmBYu7N4RWtRL5HPXCklYg3UBUqN1H2FDuYj0sxhRsEGcS2ouwRPI61UUPSCMh0P7tTl4ESQX2aw51Iq0twsDydU4pntWE8x1MHt8/UgBjfwuFXvHUswigOjtvxRC/61U8xY4nfXHzcYbUjCDo75N8XwnfpkCnYqQsGJfcGvZ09tl3U9Hzyq9bibSMxp8of+y0i7p5a6L75lo/MH98vNZw1osd6FYYYuwaxR74b+ImzBYwG3g2e2KxJRZH9niVqeqffkFNTnH5tK78xIAf5HveVVBH5ogLEixg5zuVCUg9ODiOQ0J6IqPxT9uTjFtV7u2w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=AINhbha6E3GTdJOoRKH2ne8Q4O6aSfY/BRwpeJacKqo=; b=bIi+p1532lkqrvFV3OTPjd0nbp/TOeOFz7vOgq7uIUbi1sDvKu18RhRx7BPJqU3HT3REuRZhuVwfXHmKLNGrc+ZSyentL//8kSBKsn36ZAf6CPBS7QMznFmBC5hR409FucqkU0tjbJyShw9DHph4Cos4buFkggzUu6da9XtoRpg= Authentication-Results: linutronix.de; dkim=none (message not signed) header.d=none;linutronix.de; dmarc=none action=none header.from=oracle.com; Received: from DM6PR10MB3148.namprd10.prod.outlook.com (2603:10b6:5:1a4::21) by DM6PR10MB3308.namprd10.prod.outlook.com (2603:10b6:5:1ab::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14; Mon, 20 Sep 2021 10:37:47 +0000 Received: from DM6PR10MB3148.namprd10.prod.outlook.com ([fe80::6124:acae:c33e:1708]) by DM6PR10MB3148.namprd10.prod.outlook.com ([fe80::6124:acae:c33e:1708%6]) with mapi id 15.20.4523.018; Mon, 20 Sep 2021 10:37:47 +0000 From: David Edmondson To: linux-kernel@vger.kernel.org Cc: "H. Peter Anvin" , Vitaly Kuznetsov , x86@kernel.org, Joerg Roedel , Ingo Molnar , kvm@vger.kernel.org, Paolo Bonzini , Jim Mattson , Borislav Petkov , Sean Christopherson , Thomas Gleixner , Wanpeng Li , David Matlack , David Edmondson Subject: [PATCH v6 2/4] KVM: x86: Get exit_reason as part of kvm_x86_ops.get_exit_info Date: Mon, 20 Sep 2021 11:37:35 +0100 Message-Id: <20210920103737.2696756-3-david.edmondson@oracle.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920103737.2696756-1-david.edmondson@oracle.com> References: <20210920103737.2696756-1-david.edmondson@oracle.com> X-ClientProxiedBy: LO2P265CA0149.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9::17) To DM6PR10MB3148.namprd10.prod.outlook.com (2603:10b6:5:1a4::21) MIME-Version: 1.0 Received: from disaster-area.hh.sledj.net (2001:8b0:bb71:7140:64::1) by LO2P265CA0149.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14 via Frontend Transport; Mon, 20 Sep 2021 10:37:44 +0000 Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id 1e34cf3e; Mon, 20 Sep 2021 10:37:38 +0000 (UTC) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 91a5a7e6-a665-4d79-e601-08d97c22afb2 X-MS-TrafficTypeDiagnostic: DM6PR10MB3308: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gUDBsWLFJkKJ9GNDcnGbKo3oyXGWPeZ57tAxcNkPJ5bSVH8csyX8txvhaWsqe0OsmoKKVRNXPA82/VGn9zuX3rS308m8JlNe8J8tK5aNxSPDHoTJQ850k+3g7oeMUZx3R6jtg0EKdGZWwgYHLt+/tcochcPylfED/2VehIC/+82VfmFrMhD/3A9VuqgSz52xWIx7EaeGGlQLOdQhz1+3RpIM7BHvWRdVS8VJYasdbysp+B5xB3g2eF5oAXd6x1RJrzgC0leTElZt2KqJizIVSwZvTQDii+xJ/Xu0P6uLqgmzjEf2+8u31z+xERdwan+1lLltP7xo6873B1dp4VngBax6UO+vQ4/lMnhdNAqSFYz5chGYc6JEt9FoUiLBwXZn8tRfl1QYUb/hJymZ5qgUFz2yhD/SM0CxJjXevmWEhYYSNckb8kjiCJ8cArMPomWmiL9j4iPIsHYK2QTPgLXQy9pHzE6M8tEz9w/NASuqw80dc9TBDybH3n/0HWXK9H9GR4pEVOs5e1kFhaKgjAZomMqLpELuAGYNQEF0HXgmJlG36b5wUjA+7KKc5oIsZibWL2CC20KLKECY07EGKKEi75L0/UrbbFXco3kc+2b9IrNeoghirAW0VKNyFIF49EMRdTw9GfEODEwJzVs/oeQglw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB3148.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(396003)(366004)(136003)(39860400002)(346002)(376002)(44832011)(36756003)(107886003)(1076003)(8936002)(7416002)(8676002)(83380400001)(186003)(4326008)(52116002)(5660300002)(6916009)(66476007)(6666004)(66556008)(2906002)(2616005)(316002)(38100700002)(54906003)(86362001)(478600001)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: P9cf1i8HkJt2fPLl0yZFYS0SnSZZaUBbGLU2yRx4VgvxuAOSfCLNZVeKmG7X6pg1ZEuZ/d6umrxwhavnTrZTmFfsTD6fbAStI9YjIfNgQMq/ipPUbw817v+WJZgxYKzUCJalDehU3CeWaML9UxiOhmP/61u/wqQVzk4bBaxxNiCseWNf8JWBlxTblIhykJniozuTlYDWLGr3KAyCRgdsr8PWCE1/zunaSTrXkqB5Grmc8MRL1zLF/ZHomFs79tFsf3rN27yhu8Rc5D2HGGKZVCgw9S47SSh6TCuDgFYYWTBNrWf8mTqgnsaS0gZ1t79B5oOuH4DF9etwidkmAEqZR0GHb10VTR3RuvIzf4Fr/rgp7VQkNtee4rLtpDeI4DyPp1ABt5YwgCzhB473RqOx3b9ncuDpEu0GPfC2m6wekf6ZjjW5lQiQm3WD+LqXnfVQfxFLcWWGXhRyU1Lr24hNQDrqWZqpvC+tpqvqCRP6swHIfXsRyHZYpuuYavd4xXhTKNfbJr0MljB0Inq4+z7YswcI7dnciH2k2zoG/MBFe7EW0lVqk2V8VaDBVcqTqfgooQzrYnX5NZFlkf/tJu2fj6AITzQs8Elb19OSZfTNCZFjUlmyn79WvK863q8GiRQZMK0hkfVFMcFnPr2DCzg+sqSsM07zBgMRS1/6XuhmK97Rpy+Sy0TLH6HNdKduHL74848Wnnb6FntO0KXsfleE4Zffd1RmvyHGSviGyEKP9MbGHJDia0HZWfHfFdli/50VeE70q8Ca1wksb7/FCqMp7kGBf0Jln4PM3R57UzzdlivHF2Zug5+0NUQ6lHrK8DQA77dcybnBvw1c6lwv+mL4M/RtpjeUEFdLVSNObV737qRJwAk4sDa5ZnhzkJSFTyj8/kQDktmGiEqqTH4AfEEWvquQrhGCuLsDnS1sXIPiHF4O7vkFDwcGpgQH0gNczWrSQf8YV0kzQMiB4IIBwzIHCdiEH9UxThVaRlXdYh8qikwq4/lc55amSvMjlJnjaPoC9K9oGqen04LxAPqncnd5WXgeoGN9+zG+tnBFCdiJdNFwXSzxIE13m0U+r3AnHO1uQ5bRK7D/PTntW9WYyXzbwdMXrCk/Nv3UcA5rdQVCDb++YwUZQwQzIVp6EQzQIqZDJu2NLS53++oPgRM/pfEvNfAf4vwNxdswzHWv/4CcBiAoPF+m8oK35xyD11oVT6ddRZmQvtFg/WkdWSYjv86dozIw4y7EihTk6PnoUbNPMQf0wH218ZFE8uMhEHJ+sPsmJOmOn+gfIQCj58S1SSF9bR36O87xmS28qcLIEOD96tgtsvDd9jcuYFo1o8QJmg4wGNBoa4AAP3Sa6+F++aAvEA== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 91a5a7e6-a665-4d79-e601-08d97c22afb2 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB3148.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2021 10:37:46.9344 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: v2QB62Gyz1HEf8Xn1IPzMxuIHsP9V/9kga6fhrbckg+EXQOr9Hx3eCNCE666UqJtWZWDbDC5/OD0+kg/cZs/NwnjbwacRO7rYRYwZrxeNEA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR10MB3308 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10112 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 suspectscore=0 spamscore=0 bulkscore=0 adultscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109030001 definitions=main-2109200064 X-Proofpoint-GUID: 8mP0FWU29PPAm1HfgFKy2qLwjCoUgIlI X-Proofpoint-ORIG-GUID: 8mP0FWU29PPAm1HfgFKy2qLwjCoUgIlI Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Extend the get_exit_info static call to provide the reason for the VM exit. Modify relevant trace points to use this rather than extracting the reason in the caller. Signed-off-by: David Edmondson Reviewed-by: Sean Christopherson --- arch/x86/include/asm/kvm_host.h | 7 ++++--- arch/x86/kvm/svm/svm.c | 8 +++++--- arch/x86/kvm/trace.h | 9 +++++---- arch/x86/kvm/vmx/nested.c | 2 +- arch/x86/kvm/vmx/vmx.c | 6 ++++-- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index f8f48a7ec577..d22bbeb48f66 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1405,10 +1405,11 @@ struct kvm_x86_ops { void (*write_tsc_multiplier)(struct kvm_vcpu *vcpu, u64 multiplier); /* - * Retrieve somewhat arbitrary exit information. Intended to be used - * only from within tracepoints to avoid VMREADs when tracing is off. + * Retrieve somewhat arbitrary exit information. Intended to + * be used only from within tracepoints or error paths. */ - void (*get_exit_info)(struct kvm_vcpu *vcpu, u64 *info1, u64 *info2, + void (*get_exit_info)(struct kvm_vcpu *vcpu, u32 *reason, + u64 *info1, u64 *info2, u32 *exit_int_info, u32 *exit_int_info_err_code); int (*check_intercept)(struct kvm_vcpu *vcpu, diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 05e8d4d27969..a902a767f722 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -3272,11 +3272,13 @@ int svm_invoke_exit_handler(struct kvm_vcpu *vcpu, u64 exit_code) return svm_exit_handlers[exit_code](vcpu); } -static void svm_get_exit_info(struct kvm_vcpu *vcpu, u64 *info1, u64 *info2, +static void svm_get_exit_info(struct kvm_vcpu *vcpu, u32 *reason, + u64 *info1, u64 *info2, u32 *intr_info, u32 *error_code) { struct vmcb_control_area *control = &to_svm(vcpu)->vmcb->control; + *reason = control->exit_code; *info1 = control->exit_info_1; *info2 = control->exit_info_2; *intr_info = control->exit_int_info; @@ -3293,7 +3295,7 @@ static int handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath) struct kvm_run *kvm_run = vcpu->run; u32 exit_code = svm->vmcb->control.exit_code; - trace_kvm_exit(exit_code, vcpu, KVM_ISA_SVM); + trace_kvm_exit(vcpu, KVM_ISA_SVM); /* SEV-ES guests must use the CR write traps to track CR registers. */ if (!sev_es_guest(vcpu->kvm)) { @@ -3306,7 +3308,7 @@ static int handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath) if (is_guest_mode(vcpu)) { int vmexit; - trace_kvm_nested_vmexit(exit_code, vcpu, KVM_ISA_SVM); + trace_kvm_nested_vmexit(vcpu, KVM_ISA_SVM); vmexit = nested_svm_exit_special(svm); diff --git a/arch/x86/kvm/trace.h b/arch/x86/kvm/trace.h index 03ebe368333e..953b0fcb21ee 100644 --- a/arch/x86/kvm/trace.h +++ b/arch/x86/kvm/trace.h @@ -288,8 +288,8 @@ TRACE_EVENT(kvm_apic, #define TRACE_EVENT_KVM_EXIT(name) \ TRACE_EVENT(name, \ - TP_PROTO(unsigned int exit_reason, struct kvm_vcpu *vcpu, u32 isa), \ - TP_ARGS(exit_reason, vcpu, isa), \ + TP_PROTO(struct kvm_vcpu *vcpu, u32 isa), \ + TP_ARGS(vcpu, isa), \ \ TP_STRUCT__entry( \ __field( unsigned int, exit_reason ) \ @@ -303,11 +303,12 @@ TRACE_EVENT(name, \ ), \ \ TP_fast_assign( \ - __entry->exit_reason = exit_reason; \ __entry->guest_rip = kvm_rip_read(vcpu); \ __entry->isa = isa; \ __entry->vcpu_id = vcpu->vcpu_id; \ - static_call(kvm_x86_get_exit_info)(vcpu, &__entry->info1, \ + static_call(kvm_x86_get_exit_info)(vcpu, \ + &__entry->exit_reason, \ + &__entry->info1, \ &__entry->info2, \ &__entry->intr_info, \ &__entry->error_code); \ diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index ccb03d69546c..43ea97b3f8e6 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -6059,7 +6059,7 @@ bool nested_vmx_reflect_vmexit(struct kvm_vcpu *vcpu) goto reflect_vmexit; } - trace_kvm_nested_vmexit(exit_reason.full, vcpu, KVM_ISA_VMX); + trace_kvm_nested_vmexit(vcpu, KVM_ISA_VMX); /* If L0 (KVM) wants the exit, it trumps L1's desires. */ if (nested_vmx_l0_wants_exit(vcpu, exit_reason)) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 0c2c0d5ae873..99f8f7c4a510 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -5628,11 +5628,13 @@ static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu) = { static const int kvm_vmx_max_exit_handlers = ARRAY_SIZE(kvm_vmx_exit_handlers); -static void vmx_get_exit_info(struct kvm_vcpu *vcpu, u64 *info1, u64 *info2, +static void vmx_get_exit_info(struct kvm_vcpu *vcpu, u32 *reason, + u64 *info1, u64 *info2, u32 *intr_info, u32 *error_code) { struct vcpu_vmx *vmx = to_vmx(vcpu); + *reason = vmx->exit_reason.full; *info1 = vmx_get_exit_qual(vcpu); if (!(vmx->exit_reason.failed_vmentry)) { *info2 = vmx->idt_vectoring_info; @@ -6769,7 +6771,7 @@ static fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu) if (likely(!vmx->exit_reason.failed_vmentry)) vmx->idt_vectoring_info = vmcs_read32(IDT_VECTORING_INFO_FIELD); - trace_kvm_exit(vmx->exit_reason.full, vcpu, KVM_ISA_VMX); + trace_kvm_exit(vcpu, KVM_ISA_VMX); if (unlikely(vmx->exit_reason.failed_vmentry)) return EXIT_FASTPATH_NONE; From patchwork Mon Sep 20 10:37:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Edmondson X-Patchwork-Id: 12505071 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=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,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 E66BBC433EF for ; Mon, 20 Sep 2021 10:38:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C9526610A1 for ; Mon, 20 Sep 2021 10:38:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236321AbhITKkX (ORCPT ); Mon, 20 Sep 2021 06:40:23 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:32024 "EHLO mx0b-00069f02.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235968AbhITKkJ (ORCPT ); Mon, 20 Sep 2021 06:40:09 -0400 Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 18KAOUVi018022; Mon, 20 Sep 2021 10:37:50 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=wRwqay7ePBpqK40KF/hvYgmQ0kn+OTwxHDIO7fVzWB0=; b=eyfYw5LjM9NTzpa7gm/MYjMx6SFZNAecjEh6e1+fPp2xUKQuU73kBak4sA6kQp2V+R1+ KpQhQ78em7YwlUkYed4HzXyb+ZT8vsJM1VwhrmH5xDO2drMKjiwhPTYMaeJQZxLUs7yR 6RKCYITVW1ByWFS8Bvok+8p4TSWeb3utzOMB9DdMRKFuJwWep9ImJ/hLckqGpPw93Hbw p9Z6y0ZmT1TfZxD7dSFwniuU27khbhRVLmEX9lgHDQz5FRmsuqXSAsy7t+Rt9P712fXU gi+SAREaye/WCgcmMqGwHsnNnMRqYaVLQjr1QfiLV83pJOb4Yi20c27rP6uC+V40Jmqe Cw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2020-01-29; bh=wRwqay7ePBpqK40KF/hvYgmQ0kn+OTwxHDIO7fVzWB0=; b=dVVAF2J8/QDcqd/8JKW0Ji7j4c56SFtlLIgLGc0uZanTpxvbDyWyuk+NHJTq6MvbXDwL lTl7VuuZVYlZKhXSVaxMUmitBf06Qke2XfLwxG42po1lyYglXiSeTLq6zMP9RcZqUTzV kLTl0mtkUAC75tKoGmJ5jGLMoS9251gmlFuMTuBfNGNqh89TWjCEzPjCJ7Ekq9sqgy3E VAj77iI7I3YnQjNbjPaie7vqJ/i1s2I9mnQVllO/jL4Rb9wDc0U3uwK8jaTIj++aLWl2 HW8uxgfAj936qSwEXy6ziT136KIIMKtx3UzZ6Kisd/X4E043KtVxDkSOdYDKn09TaYTz 8Q== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3b66gn1tm4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 20 Sep 2021 10:37:50 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 18KAVTOq106020; Mon, 20 Sep 2021 10:37:49 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2170.outbound.protection.outlook.com [104.47.55.170]) by userp3030.oracle.com with ESMTP id 3b557vbvc6-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 20 Sep 2021 10:37:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AlX1i+++SsHxym2Nn9x1s01KWKoD3KZbcf54QRDjgiv6I2+tE3o6CUAqpNriQc8WZXWrfisl6ntDvfzSbGKDL2Abxz4+ScDwQoVRSnbmr88XbVpNZjZQ1yAKebc2aFpsjKX84BGYGjojJHuZI7BCT3O4CZE9AsBtK9G0tBgGEw0RzTc60K3UzQsuP29PWhlmILKSWJUNCIJj4ghFpe/EAP63LGRrRVAKt13uaNUIBwFahMLsvI7Yexv0mDv0I7Eu1y8OJ3+6ESuwDLEpASepxVo8kC1Fl3uefnXN4VCB2P3eGejsqBIfyf5PrNjztWrYqeKlpJAfttt09sa+gwwXQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=wRwqay7ePBpqK40KF/hvYgmQ0kn+OTwxHDIO7fVzWB0=; b=b8DRTcEWHws5uQPf7P1n9uLAOye/G+S/qpPglSFm/ugGAIvWOKtsayFCpGR80NwT+ebkfse9mV3YMGHqXErx6XCf+6YuSSWP53/c9rY2RR+aEIOHLD/pHpFVxU3sQbXnnW9YasQQMW05tJCFDHkJnNZy9b82r8F8ctBflubxwCLdUh54bzrWWhVhccjQAYu17aDBiN7jfpPfInq1ZPN4OGV77d1t0NbsQSsQbdjShXR4JycmJZMLs9bO1u/sLqVYjpgwrq5d6V/8M/NTauSsQoV5AMBOTyUiukGnDzCi/V3ceMVxInt7sIvbIFkr9R+GvwCd+miCjfil2QSzjn+5iw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wRwqay7ePBpqK40KF/hvYgmQ0kn+OTwxHDIO7fVzWB0=; b=LN/yvylGEdn4y76NgWxGVkrnGRGS64F5SePrfvwoiKT3i3ntL1LUduerkkCB9IHsVOomKSKLWKMZMxmyDsNrPSPGR03LazYzjO2mEDMDjt8qVVQMOqJucSLfczQwFReXn7iUwxq02LRiK9+mJKDKtyrUUOLkTPUnXyntEaz5TU4= Authentication-Results: zytor.com; dkim=none (message not signed) header.d=none;zytor.com; dmarc=none action=none header.from=oracle.com; Received: from DM6PR10MB3148.namprd10.prod.outlook.com (2603:10b6:5:1a4::21) by DM6PR10MB3308.namprd10.prod.outlook.com (2603:10b6:5:1ab::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14; Mon, 20 Sep 2021 10:37:47 +0000 Received: from DM6PR10MB3148.namprd10.prod.outlook.com ([fe80::6124:acae:c33e:1708]) by DM6PR10MB3148.namprd10.prod.outlook.com ([fe80::6124:acae:c33e:1708%6]) with mapi id 15.20.4523.018; Mon, 20 Sep 2021 10:37:47 +0000 From: David Edmondson To: linux-kernel@vger.kernel.org Cc: "H. Peter Anvin" , Vitaly Kuznetsov , x86@kernel.org, Joerg Roedel , Ingo Molnar , kvm@vger.kernel.org, Paolo Bonzini , Jim Mattson , Borislav Petkov , Sean Christopherson , Thomas Gleixner , Wanpeng Li , David Matlack , David Edmondson , Joao Martins Subject: [PATCH v6 3/4] KVM: x86: On emulation failure, convey the exit reason, etc. to userspace Date: Mon, 20 Sep 2021 11:37:36 +0100 Message-Id: <20210920103737.2696756-4-david.edmondson@oracle.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920103737.2696756-1-david.edmondson@oracle.com> References: <20210920103737.2696756-1-david.edmondson@oracle.com> X-ClientProxiedBy: LO2P265CA0036.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:61::24) To DM6PR10MB3148.namprd10.prod.outlook.com (2603:10b6:5:1a4::21) MIME-Version: 1.0 Received: from disaster-area.hh.sledj.net (2001:8b0:bb71:7140:64::1) by LO2P265CA0036.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:61::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.16 via Frontend Transport; Mon, 20 Sep 2021 10:37:45 +0000 Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id ca669824; Mon, 20 Sep 2021 10:37:38 +0000 (UTC) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 56cf57c0-1ac7-4b93-0fad-08d97c22b009 X-MS-TrafficTypeDiagnostic: DM6PR10MB3308: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VEnW14fpaghJkloMGB2jHP+VCueA8BnB4pKJwcjaDmLwtv/0Hb1g606wyeoZ5Bmf/87k5V7UeI1rsA8x39s2OswyoZLk8P1FWuES9dcnkWUKgaIjgfOK8384nDJmroAJu6kQf98Xzd8yHXuAIY2g9I3O1Z5Kkp6ylziIdoOP6EUJMilmQQaG/2nRf02HB7Z+eFz1yop0Mo0LFac9h4x91lRlFVOppW64htVlZQdL27XaTK4wbubpQSNSgrLkF3JsIi8sj9hCQgxBYf8gTiqVBAQsAvu5j4p6d/ChkGgRGEngtNR12V/rVdJkx96hV/B7VcXmYsG9w7fzO/0/KdIEeyuRsYyN1crogkjYuKGIHaY8vqjTi+9gPXs5QMDotB11OBy+vPswnyN4nhXqfVCMrJR2MQpRIrwIlqanYmr10PpEKNt0hSqrrvJGoGhpf+2CWdH4q8ynXHqgYvWuYF/ZxeyH5yOT+A8k01SIDUuqxAq0Ju/yqIKA6cejqB4bf74qLzZEugtS5J1ieQSI3erCY+9p9uWQ/2E6/b5AsdOCtstu8Ly3b36UK99lEJ3VIy592lsx3VuYX41W1XT2bPjIvCs0/u2rOFSrIKXjg80BdjFgloONHTmK+L7qWAD74ZDfOZSETxJmrgW038G+H056TA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB3148.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(396003)(366004)(136003)(39860400002)(346002)(376002)(44832011)(36756003)(107886003)(1076003)(8936002)(7416002)(8676002)(83380400001)(186003)(4326008)(52116002)(5660300002)(6916009)(66476007)(66556008)(2906002)(2616005)(316002)(38100700002)(54906003)(86362001)(478600001)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: CkURCeXLVrOwsCdzgRYKHjwDFhu6wFdjbGIUoYjDwTzKkCgnH8oYYl3HvQrhamlgk5ix6bqNwG3aek+0HuhbPA5Lxno4NymwoHbada5waCGCYRQqhYPwsUW7fjNByhK4sMLsP9nO9y28ERCrX7Fg0f/9/+40YyLetzCOQ3xQY/vxLPX8NcttftK1TL9Z3MoPaFVgVKRRRGUQ+lDVpm8DB5l0c+yEn/OMRHvmO9Uh1Wkx7BFeiA8l9F/f2eGOBTb4H8UasDmYRG/wxWNkoMpDD8t1V7IjtQJCT+Hc/+F8YWjOpwcz/LSAAE7IbIx94iwr7KB9DH+l8FOVt6O35ZTyEBAonzLGEEfl3FBkrw1VNIdRn7vXeJgTLSJbJ7e/TOt0MkbHQnwQEL08Yog4gWgbTMUJnYuEEiwwXeNXYD0ctw9MPM17g0XiIay+rt/h5Otv2hIHBlvlzKb/BiHmReWW74frtj8qjvD6kkJ3AQDqRfScgt1kFFpwn8mmH8EKKkraicj3TnpidbXG+N1X/gILv/ROzc8oOjkkUq+qcy8nhoBPb8xmSZ4HXuxfLHOtnJM3j/EXMQiopruv+nsx3nU4oY6vOoX5FQTiN0aB49lLy02cXFwG1ST8UUHzTU9H1BGHHQsqarHM843tlLA7axlCXgHodWiietPwTMTNVpAEwMEhvzV8VQNL8jR5jBAkg1zx60UxyFgbc3VNiVC06cXcG5s9vs2DyTDP8rCef6RUfbcocSiRKuoUQOxQiRjINLfHIdc4teT4SezkP2bJ3B6nPSZNtzTf4BisfpsDL1tWFoiOBtB1DTZf6RSq7cuMOUG4pRVudRgiIqfQmb16+RAJoaHN/o45J+/eF9C7f8BdNJ+uX6AM+AJECw21MQwryUAZ0RCTNJM3mfHwgx+xd92kB01xJKXZQgUL2aRm7HZEvCdPxVvL5Jkib36QTWkH2dWDepfW0KXT/T59H8XATtJt7dxATaQTySoVuwLW5uED2D3UtOGiAy+7GPh+CMdpNjztu3iUGnluEdm1BENPbOraXTQIP7oDs0KWV/T8a0YVUmQ4SX8Hu+Svwh01LmHIjC6voMzR0Nap4vf9mEodHbZIhxH4qPtMiBlJyaU5RjmHM03ff7q+qof+Y+FBsIR/rjqupO/jex03oWMlGLSq8g5Te1aSWDToIUnFpNAiemrVtzQZVhlI6BDe8sVrJusEVERXvVlyt4OQBCwDRj3lBH2y20Tzi2DV1SLPncoz+6yLsi+Ad2G6AD3ySVn/hDVjGE89rleDaKCh1epskkD8uA3xeqRIyhias+F1dgZ1vc/nQ/BtrxmiIH+DxGtIx0sTJYexEBDlOZIAz7ezNTXSXkm+7g== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 56cf57c0-1ac7-4b93-0fad-08d97c22b009 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB3148.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2021 10:37:47.4501 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: IzWRAXIOe4xie2M8Cus0/44Pp4+JivA5Dhysy6oXnWGEKYRU5LteewKSL+JawcDAtgvFV2gR1wK++WncgJv2B2HNzOLI8eCzH4BxXEjrwhU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR10MB3308 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10112 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 suspectscore=0 spamscore=0 bulkscore=0 adultscore=0 mlxlogscore=828 malwarescore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109030001 definitions=main-2109200064 X-Proofpoint-GUID: VEvZvCFCFwESt0Prwq6nlAQBQ0v9hBjc X-Proofpoint-ORIG-GUID: VEvZvCFCFwESt0Prwq6nlAQBQ0v9hBjc Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Should instruction emulation fail, include the VM exit reason, etc. in the emulation_failure data passed to userspace, in order that the VMM can report it as a debugging aid when describing the failure. Suggested-by: Joao Martins Signed-off-by: David Edmondson Reviewed-by: Sean Christopherson --- arch/x86/include/asm/kvm_host.h | 3 ++ arch/x86/kvm/vmx/vmx.c | 5 +-- arch/x86/kvm/x86.c | 73 ++++++++++++++++++++++++++------- include/uapi/linux/kvm.h | 6 +++ 4 files changed, 69 insertions(+), 18 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index d22bbeb48f66..297581046460 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1658,6 +1658,9 @@ extern u64 kvm_mce_cap_supported; int kvm_emulate_instruction(struct kvm_vcpu *vcpu, int emulation_type); int kvm_emulate_instruction_from_buffer(struct kvm_vcpu *vcpu, void *insn, int insn_len); +void __kvm_prepare_emulation_failure_exit(struct kvm_vcpu *vcpu, + u64 *data, u8 ndata); +void kvm_prepare_emulation_failure_exit(struct kvm_vcpu *vcpu); void kvm_enable_efer_bits(u64); bool kvm_valid_efer(struct kvm_vcpu *vcpu, u64 efer); diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 99f8f7c4a510..e71f6ccafa5f 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -5378,10 +5378,7 @@ static int handle_invalid_guest_state(struct kvm_vcpu *vcpu) if (vmx->emulation_required && !vmx->rmode.vm86_active && vcpu->arch.exception.pending) { - vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR; - vcpu->run->internal.suberror = - KVM_INTERNAL_ERROR_EMULATION; - vcpu->run->internal.ndata = 0; + kvm_prepare_emulation_failure_exit(vcpu); return 0; } diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 28ef14155726..55fe3203a3c1 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -7468,29 +7468,78 @@ void kvm_inject_realmode_interrupt(struct kvm_vcpu *vcpu, int irq, int inc_eip) } EXPORT_SYMBOL_GPL(kvm_inject_realmode_interrupt); -static void prepare_emulation_failure_exit(struct kvm_vcpu *vcpu) +static void prepare_emulation_failure_exit(struct kvm_vcpu *vcpu, u64 *data, + u8 ndata, u8 *insn_bytes, u8 insn_size) { - struct x86_emulate_ctxt *ctxt = vcpu->arch.emulate_ctxt; - u32 insn_size = ctxt->fetch.end - ctxt->fetch.data; struct kvm_run *run = vcpu->run; + u64 info[5]; + u8 info_start; + + /* + * Zero the whole array used to retrieve the exit info, as casting to + * u32 for select entries will leave some chunks uninitialized. + */ + memset(&info, 0, sizeof(info)); + + static_call(kvm_x86_get_exit_info)(vcpu, (u32 *)&info[0], &info[1], + &info[2], (u32 *)&info[3], + (u32 *)&info[4]); run->exit_reason = KVM_EXIT_INTERNAL_ERROR; run->emulation_failure.suberror = KVM_INTERNAL_ERROR_EMULATION; - run->emulation_failure.ndata = 0; + + /* + * There's currently space for 13 entries, but 5 are used for the exit + * reason and info. Restrict to 4 to reduce the maintenance burden + * when expanding kvm_run.emulation_failure in the future. + */ + if (WARN_ON_ONCE(ndata > 4)) + ndata = 4; + + /* Always include the flags as a 'data' entry. */ + info_start = 1; run->emulation_failure.flags = 0; if (insn_size) { - run->emulation_failure.ndata = 3; + BUILD_BUG_ON((sizeof(run->emulation_failure.insn_size) + + sizeof(run->emulation_failure.insn_bytes) != 16)); + info_start += 2; run->emulation_failure.flags |= KVM_INTERNAL_ERROR_EMULATION_FLAG_INSTRUCTION_BYTES; run->emulation_failure.insn_size = insn_size; memset(run->emulation_failure.insn_bytes, 0x90, sizeof(run->emulation_failure.insn_bytes)); - memcpy(run->emulation_failure.insn_bytes, - ctxt->fetch.data, insn_size); + memcpy(run->emulation_failure.insn_bytes, insn_bytes, insn_size); } + + memcpy(&run->internal.data[info_start], info, sizeof(info)); + memcpy(&run->internal.data[info_start + ARRAY_SIZE(info)], data, + ndata * sizeof(data[0])); + + run->emulation_failure.ndata = info_start + ARRAY_SIZE(info) + ndata; } +static void prepare_emulation_ctxt_failure_exit(struct kvm_vcpu *vcpu) +{ + struct x86_emulate_ctxt *ctxt = vcpu->arch.emulate_ctxt; + + prepare_emulation_failure_exit(vcpu, NULL, 0, ctxt->fetch.data, + ctxt->fetch.end - ctxt->fetch.data); +} + +void __kvm_prepare_emulation_failure_exit(struct kvm_vcpu *vcpu, u64 *data, + u8 ndata) +{ + prepare_emulation_failure_exit(vcpu, data, ndata, NULL, 0); +} +EXPORT_SYMBOL_GPL(__kvm_prepare_emulation_failure_exit); + +void kvm_prepare_emulation_failure_exit(struct kvm_vcpu *vcpu) +{ + __kvm_prepare_emulation_failure_exit(vcpu, NULL, 0); +} +EXPORT_SYMBOL_GPL(kvm_prepare_emulation_failure_exit); + static int handle_emulation_failure(struct kvm_vcpu *vcpu, int emulation_type) { struct kvm *kvm = vcpu->kvm; @@ -7505,16 +7554,14 @@ static int handle_emulation_failure(struct kvm_vcpu *vcpu, int emulation_type) if (kvm->arch.exit_on_emulation_error || (emulation_type & EMULTYPE_SKIP)) { - prepare_emulation_failure_exit(vcpu); + prepare_emulation_ctxt_failure_exit(vcpu); return 0; } kvm_queue_exception(vcpu, UD_VECTOR); if (!is_guest_mode(vcpu) && static_call(kvm_x86_get_cpl)(vcpu) == 0) { - vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR; - vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_EMULATION; - vcpu->run->internal.ndata = 0; + prepare_emulation_ctxt_failure_exit(vcpu); return 0; } @@ -12153,9 +12200,7 @@ int kvm_handle_memory_failure(struct kvm_vcpu *vcpu, int r, * doesn't seem to be a real use-case behind such requests, just return * KVM_EXIT_INTERNAL_ERROR for now. */ - vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR; - vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_EMULATION; - vcpu->run->internal.ndata = 0; + kvm_prepare_emulation_failure_exit(vcpu); return 0; } diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 8618fe973215..cb032a95aca2 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -397,6 +397,11 @@ struct kvm_run { * "ndata" is correct, that new fields are enumerated in "flags", * and that each flag enumerates fields that are 64-bit aligned * and sized (so that ndata+internal.data[] is valid/accurate). + * + * Space beyond the defined fields may be used to store arbitrary + * debug information relating to the emulation failure. It is + * accounted for in "ndata" but the format is unspecified and is + * not represented in "flags". Any such information is *not* ABI! */ struct { __u32 suberror; @@ -408,6 +413,7 @@ struct kvm_run { __u8 insn_bytes[15]; }; }; + /* Arbitrary debug data may follow. */ } emulation_failure; /* KVM_EXIT_OSI */ struct { From patchwork Mon Sep 20 10:37:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Edmondson X-Patchwork-Id: 12505075 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=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,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 D744AC433F5 for ; Mon, 20 Sep 2021 10:39:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BEF3761107 for ; Mon, 20 Sep 2021 10:39:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236418AbhITKk0 (ORCPT ); Mon, 20 Sep 2021 06:40:26 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:46792 "EHLO mx0a-00069f02.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236146AbhITKkO (ORCPT ); Mon, 20 Sep 2021 06:40:14 -0400 Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 18KAI2p4028074; Mon, 20 Sep 2021 10:37:53 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2021-07-09; bh=jxlL0lGtv5ZlNrPQbf90760XLEjt/UFew72/NT7P6ZA=; b=ujdmjK/3aRQl7ojMwwnSErwE0kxBS+lRRnSteqzqWpeDqIJpN9hA7HfeD6q/K5H54CwV TrQ28fYkFePqZPDUtwZj148pt9RnhV5ArjgGqft3l2vF0IPy70aoGk0+R8ajJdErAOv+ 7oMjPnj12rGYDL9utqRRUegk2pop64u7hudANvCp9pdaqugcwZyes0eFPX0nGUEDKMTK gcfXtmzL7CIazQeMeYdooYhEiP259CeAUknzJCGZ+Y951BuLRVn9B0/7vjlSAGa7ubas akwHFBknaxl5CXY3sZnezVCbpIxBJUNG6k92KegY7v2IduI+zDnpvCBxy9s+IG6k5piP Ig== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2020-01-29; bh=jxlL0lGtv5ZlNrPQbf90760XLEjt/UFew72/NT7P6ZA=; b=KGTJSGlU7p483qNxhSaoGccNsfhoVx+Sx5gqRs0OeIlehhVJCSv2unjR/+V1oIqsK6gG fsBUiYR7Np3b+68v3kE3YZtytyRz8PzCGPGL8gm8kASBqoQ81ijhjFQyDuRgI9c4yLf6 A3WNZPGEIq1LKs+Bqspa747ae9v7QojunSEAC90/dpGDlfYjn2qXm4HpYEjuRGfsnUdB 6QpjiXDW1P3CPMnkGtNf6cs3D4am8ZP82mMYQTVJ8lXz/MI2gUyL79hBbi8xeyUK9UfT FUOeC6j1H5byUTHXJeIHjWIBAGkYe811rqgVuNFiezQIA2Buvnv/XmCML7Y20qn00YES uw== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3b65mr9wga-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 20 Sep 2021 10:37:52 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 18KAUjl7173272; Mon, 20 Sep 2021 10:37:51 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2171.outbound.protection.outlook.com [104.47.55.171]) by aserp3020.oracle.com with ESMTP id 3b57x3urq5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 20 Sep 2021 10:37:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gAwwy4i44J4RA2oM4R+i2OGNvE7dii6ZJvd0GPCJegwtEjGjdXmP5FV5XVrPbbFktzTxmC1HctN6/jGOAJwkLWo/eDvYabBqyV2s4hofq47NxxHImO8dl538x1sItD/rtZfZeGwfOXLDAfyrHQ6c1w7NNJ6xWP3t8lx7GUjmmyG0Elg54i2LY6wdAT38PMv0/CJWDF9MqLdUVjDB3HFCHVzO4wA5x1jr4WcOCimAiD9A4DHEc5Wyd5AF9ypeo65J8LROrgafT1XSoKWtUyQGBpORSelsGtfpcB/ablPxk8mPDNuU0DcBxY19jeefRiZUZ2eX+cCunfKL4tAc3mf42g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=jxlL0lGtv5ZlNrPQbf90760XLEjt/UFew72/NT7P6ZA=; b=IEsQbPCpSjMNKVpgtJWY6TSHqFhFxXav0fGfoGbVGgvUrMM/oQQ2yXQKvycVu2ABuY2N+fGpNp6lVOLHQHAeHpvkjZdq0/5hiHmtXbSSskuH8X4GLDILAJr3ARY6XxOEZGec7ooY+hE9E35ZESgXxy11v4rH8/uhfKSFZF2tKRXD4Z1p2GRfQwXooiZq5YwI/49mR/GvJr5Ftw2Mn0P8wSYPxPifLttlLjg04IkCSLQ39CtRPIy/x9ijX2HLwpYKxXhH3CMxRk3wbwVYNb2uZJMXSkZkQl9Mku3NLh0PjuIG2Eshgl2mYxxMk6+ZqsdrWB6MMG53YTv4WbrKvPWS9g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jxlL0lGtv5ZlNrPQbf90760XLEjt/UFew72/NT7P6ZA=; b=TFEbu3TRrkh7O4yIY5ixUwYS9IFIbY50F9g92AozwyF4RP+rY/snW/DiaAqFftt2jfZ/+tJI4DiIQGgClmPX7dhcx6KbhA5KlZj1LzSR5qcTyPblDV85ezHsCDEY5Wo1y0rv7le/6AC6BKgGYjz+rQuvyqyuD+1LB4PUKg7IbK4= Authentication-Results: linutronix.de; dkim=none (message not signed) header.d=none;linutronix.de; dmarc=none action=none header.from=oracle.com; Received: from DM6PR10MB3148.namprd10.prod.outlook.com (2603:10b6:5:1a4::21) by DM6PR10MB3308.namprd10.prod.outlook.com (2603:10b6:5:1ab::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14; Mon, 20 Sep 2021 10:37:49 +0000 Received: from DM6PR10MB3148.namprd10.prod.outlook.com ([fe80::6124:acae:c33e:1708]) by DM6PR10MB3148.namprd10.prod.outlook.com ([fe80::6124:acae:c33e:1708%6]) with mapi id 15.20.4523.018; Mon, 20 Sep 2021 10:37:49 +0000 From: David Edmondson To: linux-kernel@vger.kernel.org Cc: "H. Peter Anvin" , Vitaly Kuznetsov , x86@kernel.org, Joerg Roedel , Ingo Molnar , kvm@vger.kernel.org, Paolo Bonzini , Jim Mattson , Borislav Petkov , Sean Christopherson , Thomas Gleixner , Wanpeng Li , David Matlack , David Edmondson Subject: [PATCH v6 4/4] KVM: x86: SGX must obey the KVM_INTERNAL_ERROR_EMULATION protocol Date: Mon, 20 Sep 2021 11:37:37 +0100 Message-Id: <20210920103737.2696756-5-david.edmondson@oracle.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920103737.2696756-1-david.edmondson@oracle.com> References: <20210920103737.2696756-1-david.edmondson@oracle.com> X-ClientProxiedBy: LO2P265CA0149.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9::17) To DM6PR10MB3148.namprd10.prod.outlook.com (2603:10b6:5:1a4::21) MIME-Version: 1.0 Received: from disaster-area.hh.sledj.net (2001:8b0:bb71:7140:64::1) by LO2P265CA0149.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14 via Frontend Transport; Mon, 20 Sep 2021 10:37:47 +0000 Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id 3c6f215d; Mon, 20 Sep 2021 10:37:38 +0000 (UTC) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5d595265-297a-4376-f831-08d97c22b118 X-MS-TrafficTypeDiagnostic: DM6PR10MB3308: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4125; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BkhCpPppMiImLxTgzGnEleVFiiooQF7b7B8m14gBbyEmla4/bk7ET+mTTeCFbdTaiDQjI9n05Hm8b7IlRdVaJEvxLddf4tn6NCx+rJ8T9H6ysHMPeUQW0twb4YGmEs6nBU3yCPf/A8QiUBh+SE3w/cYkv5PpW7DktdgvzE506yYJKciRJ39lyW86Y0wjzF/8EPT94GSYCD5b3ThB4ICu3Iz7icO3Gxfs4g7y8oCVb+XAKA6bhkGBTOUfrrHJY8gJvRvo6PyYgqkpgBWwg5vsQEebbGJOjii3jDy2gb6JetPuj1owRshExzTUc0TkBBbOcmUOWMy3CUJ1jlzwsaeV04QxGzyPdf17/UktubVzL2F7GF/uhU1xwsOIr5FT4tg6TtGHySm4PKWbRZOgCaYwholOzVHYJPaDIggH/JPXG57VLVZZ6eK6ZTQSIFfq550+L+Dws7ouvU4AENxskK5vCJKmaTGY1tXLvm1gQlOfufzEkpeJXoiwieFdnGEKfXhVOfSKMHSh9A7ZQAXAF6uqSp1+ZbYJTlMGKnwNPcO+TCPIznW/Ccx5Z/AspoUcRLOO+Bx2OlYsoVm5CaSktGtcjEz064l4Z6j3cPUw8uVJ9sib8Tim3LQTdgz/ryBvGE7R60qving8b1iVcQklK1qhJA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR10MB3148.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(396003)(366004)(136003)(39860400002)(346002)(376002)(44832011)(36756003)(107886003)(1076003)(8936002)(7416002)(8676002)(83380400001)(186003)(4326008)(52116002)(5660300002)(6916009)(66476007)(66556008)(2906002)(2616005)(316002)(38100700002)(54906003)(86362001)(478600001)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: i13ZJpmF0vAKyJr/n1w95zN257aePhJG3VcUCPALT+/lLvnV6sMJyzZm1FZm7RPy/trTET6YED+tJ1JHNft/GcRh//ceEpNm/eZVB96YlNrlawur3v1ymudIzbBx4AkCxBzAboj72G8JuO4UP57exgz94NJiNLkOqpb0f/WQQQKWWWVZEpmKmml4J5JTnsW3QJ1Mb8MYJcxJN93eF1GaFlNHL0oHv4ZnszHT6blJ85Hfl5+pc8Kxs4KDkTAIDol3bjdtOSKako4VkbfQtVNDEh8VI1hRi+FbQ0V/OLZUFq0rpTZWstHli/xif/+P3QH7Y7UiLtpySGVSCChsXQ8tFVmb9/XDX3l73ZzD+0eooOyWxJLPnj1Mjq1gNqR5c9DeTZpgihqm4Lhv/BudX/iGkt0CqenueFhhLvr1GRK3vGLF/4CE82rc6Kb+FBcNHtGYFlOPhJ4cI4M/gSod3FbHc1c+mgfi5CJ/BB0zhSUZ4Vjj1/mCgToiSkzMAiafeSgPmGDnEe0jf7k690m4pR0ZtvA52lQ6PlUXjRKfDoUrHwhbnQLhlfW82WR2Gnlm0MsY5+/ioYqulPHG4z7FaaWAZ/z6yC4rSqaJX+Rk0lfxflqNcUteY9UW3lWaknOCX4IV3xc4+9C5DV6Gfy80Vw+4CG8hZzVPTOFMnTTY8E6MMwMYwGvdZPeJh9Pc1OBHWIHEjqwjeFiz2n7BORcKh046KSBnIRQJvI6UCqOmf0TjUd+A/OOSzh3fwb51+U1xFA7MpayIdRfOllzPsXEjrhMy3hLVPwFUUte19AKjwLbbVaY6XrEqArNKOni92NVKbJ62lET+Zv6Tr1EcZ1AhTfoxY/CoYOu8I7TX9GdFzn7lx+3R/07sh+MEUU/HQx5FsvrqgVDERvvJXywC51fWZpf37jZP1qAprlF2AkAv08eiD7iSz/Vll4q1qDgoSC3aqGteWCRrnarggnUeyKwr1tf22KpiZcULgqiYC0z2FYjs1kvKwuX4jblUDl4XUERlEBcCRBEFQAWsyYjuPf+IMyDF8ugnXp00gr6SGML6szl4B9QM7Dz3pYvuqWtiBsJSWUXd2nlH+i7gfvP1FWJOgUBWPNntFBJv0CEYqyY2NSJITX9YDJn4wYRWF5ccoyX6oDTza8nTal6xA7RV9T5S8qDAf8CSZBdRFYTBv8zvC2RFNN03cLiuEIplaTN3NBERqjCn5GP1c3xZofQbFdVwdaZdNLtfm7aewfrbVq+Qmowo7NFTkRKONH/lOnZPoQDp+1eqEtj6M8Ef6p3BTw15R5vVsrB20Hf6LI4dxkgW1jse9OZteLA4C37p7NWrV1W0zIZ5mnD9Q+58HS6vs8pq6o74Sw== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5d595265-297a-4376-f831-08d97c22b118 X-MS-Exchange-CrossTenant-AuthSource: DM6PR10MB3148.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2021 10:37:49.2261 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: XlZdSbrwJTSnf7W26Zxelk/mHqZ8XQPFATqgj1RifFEm3Tzn0tr3X5tuo8qS8DYOGuiHXXjEJio5QjLJRYegI2KHNVJFw3jLTn3Ly7cuW3U= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR10MB3308 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10112 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxscore=0 adultscore=0 phishscore=0 spamscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109030001 definitions=main-2109200064 X-Proofpoint-GUID: rAQiC_zffUqcDE8_mw3ATGrEeG_fOHl9 X-Proofpoint-ORIG-GUID: rAQiC_zffUqcDE8_mw3ATGrEeG_fOHl9 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org When passing the failing address and size out to user space, SGX must ensure not to trample on the earlier fields of the emulation_failure sub-union of struct kvm_run. Signed-off-by: David Edmondson Reviewed-by: Sean Christopherson --- arch/x86/kvm/vmx/sgx.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/arch/x86/kvm/vmx/sgx.c b/arch/x86/kvm/vmx/sgx.c index 6693ebdc0770..35e7ec91ae86 100644 --- a/arch/x86/kvm/vmx/sgx.c +++ b/arch/x86/kvm/vmx/sgx.c @@ -53,11 +53,9 @@ static int sgx_get_encls_gva(struct kvm_vcpu *vcpu, unsigned long offset, static void sgx_handle_emulation_failure(struct kvm_vcpu *vcpu, u64 addr, unsigned int size) { - vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR; - vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_EMULATION; - vcpu->run->internal.ndata = 2; - vcpu->run->internal.data[0] = addr; - vcpu->run->internal.data[1] = size; + uint64_t data[2] = { addr, size }; + + __kvm_prepare_emulation_failure_exit(vcpu, data, ARRAY_SIZE(data)); } static int sgx_read_hva(struct kvm_vcpu *vcpu, unsigned long hva, void *data, @@ -112,9 +110,7 @@ static int sgx_inject_fault(struct kvm_vcpu *vcpu, gva_t gva, int trapnr) * but the error code isn't (yet) plumbed through the ENCLS helpers. */ if (trapnr == PF_VECTOR && !boot_cpu_has(X86_FEATURE_SGX2)) { - vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR; - vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_EMULATION; - vcpu->run->internal.ndata = 0; + kvm_prepare_emulation_failure_exit(vcpu); return 0; } @@ -155,9 +151,7 @@ static int __handle_encls_ecreate(struct kvm_vcpu *vcpu, sgx_12_0 = kvm_find_cpuid_entry(vcpu, 0x12, 0); sgx_12_1 = kvm_find_cpuid_entry(vcpu, 0x12, 1); if (!sgx_12_0 || !sgx_12_1) { - vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR; - vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_EMULATION; - vcpu->run->internal.ndata = 0; + kvm_prepare_emulation_failure_exit(vcpu); return 0; }