From patchwork Thu Apr 15 15:56:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 12205721 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,URIBL_BLOCKED,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 19083C433ED for ; Thu, 15 Apr 2021 15:56:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EB9A4611AD for ; Thu, 15 Apr 2021 15:56:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234192AbhDOP4m (ORCPT ); Thu, 15 Apr 2021 11:56:42 -0400 Received: from mail-co1nam11on2062.outbound.protection.outlook.com ([40.107.220.62]:50656 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S233939AbhDOP4l (ORCPT ); Thu, 15 Apr 2021 11:56:41 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fL/fEUEVOBjcIwaNsKNR2c4cPzD3yHsJwHRfAfSzHsaAD7cMiIj60YE8jF8XOXBgJSs6UGMewQ0HIeul+RYaVpoVbrltyeMn1dP+hKm8Be7E8aVPhu2Qu+aQ4PO23bcE/ywFan3XTMuJx2HuNUhkPdmSsrA1QOXV1vgkVHPcVAtMHFO+9dR/iA87yLvgEdfYecv8doOZ5jjO7hezyQ12HV/O64CGBvkOCYPiQZECl0I2TwURGciTpfp4ozQ/CZjWwIdDxhNwHnu/9BwbJ+ja8DAcuRNge3tQDoAuOtz6yyub8MN1LBQna4doftU15nNsAk3dUcuqlR/J6vZZzC5P4w== 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:X-MS-Exchange-SenderADCheck; bh=CLNAo19buTg3Yb1D6/ZVJBYv5MP2n7HijI3gYDV3fvM=; b=llVe5D7hyGFYB/YuXzMlI0NnAsPU5U33JtafB16KX2mq/SvqaDbELOTiXMbC2BDA2pfiNhSHw+FaN3s0qKhuU0uyI5pcPqPHFM6BqCRVj/B1qZr+Z1rxStWaf0EOqJ7e5qgJrnUywG+RLti5UM1Xe6FiA91pJjB/cWhyJqoabbzlXEEH3Obe9ysFwllG5j3C78CgU6XMZ4AuHWd7J7HC8tizTnvfFB0zDoshTtGaieKPlm1nVRUzWjl5TJ9LDMsv2ZJbmgmi4TQJqB2/ATFnKYg6nWEq7RRJlhPkXx8ulqfnCZmqQxG4uOq7B1KcOZV+TAa0t/Z6bOeSi3z8iTF+GA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CLNAo19buTg3Yb1D6/ZVJBYv5MP2n7HijI3gYDV3fvM=; b=EgGTsAAE/P+r81KC7TuYwZtPefk9D6K9Hz/FfkXlw96DmUf7OnIQ0jQj5euxXzEOQZ2EoT7sYiqOzZvln9Zg96AUSKMEOTV6dcs65bA5RGbpicbYvGA8/wGVAQyE+aUfAEy/ehOMkLDuwxCgeMLY1xIXQYIP6urWLW3fpabMdwc= Authentication-Results: redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) by SN6PR12MB2766.namprd12.prod.outlook.com (2603:10b6:805:78::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.18; Thu, 15 Apr 2021 15:56:16 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::1fb:7d59:2c24:615e]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::1fb:7d59:2c24:615e%6]) with mapi id 15.20.4042.018; Thu, 15 Apr 2021 15:56:16 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, joro@8bytes.org, bp@suse.de, thomas.lendacky@amd.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, srutherford@google.com, seanjc@google.com, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v13 07/12] KVM: x86: Add AMD SEV specific Hypercall3 Date: Thu, 15 Apr 2021 15:56:05 +0000 Message-Id: <999bdd6f4e9e2d7f4bdc20cea9459182327f505b.1618498113.git.ashish.kalra@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA0PR11CA0197.namprd11.prod.outlook.com (2603:10b6:806:1bc::22) To SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ashkalra_ubuntu_server.amd.com (165.204.77.1) by SA0PR11CA0197.namprd11.prod.outlook.com (2603:10b6:806:1bc::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16 via Frontend Transport; Thu, 15 Apr 2021 15:56:15 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ea5ff5c7-5006-4b4b-627c-08d90027004c X-MS-TrafficTypeDiagnostic: SN6PR12MB2766: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3513; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AYgdXjuBhPJ88yjqf2kbusCtx48uHiybODb4oef3KnmqgLSd4PZaDIRE9D8tU21Pxo9XT96OGFfMyX9DuD/XZdYkYTD8P1TrutGs+ftUu02yfPVg7cYQw0wugpnXPmS/EJonAfHdyHmm2/OHRHbwAccJvuv/Nse7JSpunnE89Lh92G/J+h2Pcw0JKEPkikQ+yDArvGi8oOgXQXGpcM2fdWs0JZ7M0E0Sa0ONLa4P5FHZX9yNg3OGKhBHhRmcedp7Pnnyr7fco8ccoeNA21ibuXYcAA3rhYvacN7hEsG2M/D8Pi5nIZ/h6JRj1JqaxgX+XcDov3rBK9+nLmudWfhdhwOkN0VmgCrDNByoVUxNdiQITIHUmD5RZc1OdNpry8pnR4l8igQpmIUF/YhNoub+SRdnDqrtM3jYidrIbTKiFeeGBYv08SAM2ap4RJZWkkFHUtCdgCUeIauk5mXYiKiTbO1XndeweSI76Y2WoLhrBTu8ymQ3nBqLgah5tllVUpYbUi8K+DtfkLHxR3eyZIcuDs626HQyZ54webLcVeQS9shXOE/fznrTJ2LxPqiDoI9IVex0AoRmW8iCqvxoahzNUHCteE+UoK6fdn9uMecEhb8rPDhL6uVvWhaoVY25N/nR1H2AmTBdmNhraNy0mGQaQA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2767.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(39860400002)(136003)(346002)(366004)(396003)(2616005)(6666004)(8676002)(36756003)(4326008)(316002)(52116002)(8936002)(478600001)(956004)(6916009)(6486002)(38350700002)(26005)(5660300002)(2906002)(86362001)(16526019)(7416002)(38100700002)(66946007)(7696005)(66556008)(66476007)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?ITZNETrCvWxuy4gC462p/tdrLt5oNV?= =?utf-8?q?z67r1J+LsrIaOJzs9LsbZwABM+IK1BGKfj0AVchMyyiO+/l0yeiZQBSi5whFYuzb8?= =?utf-8?q?uBw/LMylTfhBt7s6E0n2ZnwICYFeZ8n2N0FfP5CWPPcHRnAroXfR+tC3eUQlLg/eC?= =?utf-8?q?4sU00DyFcJTvjFIFJVVlgx3h8EbVRKPXEs98Y45BWFST1UI1+EfxqrHge8bwhOspr?= =?utf-8?q?CImkqDhOY+ESu2bv/5PJb7/xFWqXWnnK3PfPoF4RpbHq9dPEtwD+xfTNLiZwOwtpq?= =?utf-8?q?q61klKavhTf7/v7oOA3DWeJji+pOE/7ujzunjzM/7s2U0N2CWexLrwE+4TNRuwB0b?= =?utf-8?q?WoXsNMPWGmSN9AwBVZcy27XZCVVsJIKUPHlsMLFm7aCELX/dpCN5n3K2OBSAB6QHb?= =?utf-8?q?BLuchs5eVB+gvu00I8NcdfiAB2SeoJnytIw25vwvxO9UcPWKMn6T980BduisNGe9t?= =?utf-8?q?MdthLv4b3fW9/BExK3kcDeo60LgXaiQRJ9Prm6j4dL26oa0DEwxHcPVcFjj/kj6Ev?= =?utf-8?q?h68hau3C5V+bJLW6cvR4pUWWIR9Nqtv6XGGHJpI/qpygW68qjNHy71hroXI+4DN3q?= =?utf-8?q?1GTAIlUyVQkBsrDSSJawCWBBITPkK5LDsavEwFNG2kw6dvTr2AYxedVd8G1FCynhA?= =?utf-8?q?PXOokQJ7t1hQrWUqI7UQMQ4JD/4/qRgKNwLfA4hwhg1wtISzFr7s/GVQK0TDPjwRy?= =?utf-8?q?69/nFn/wF9NBNmxqBCArDK4JgwmHvZHabfeEbf5uSg1aPibC6HMy0z4au7TG9KQ1L?= =?utf-8?q?eNc9A51qd9iMpdQEm56sxndZo3rFcQrkiU8aIs77WVNzHhE64seycpVy5dIhJSm7B?= =?utf-8?q?vI4ukE9zI4iUAkBpl6WyRh9thK0rVrp62Js+JfPqNqxvQjJ4l/RU+ITSnLE/iEylS?= =?utf-8?q?wKw05iIaFFszsYhtOi0VFXaia5P5VqZDJY/3lXMPbRQbrHtvwp7IXBupeA3db6IPw?= =?utf-8?q?5UnrM1yNXZtwQBO3KAt2C7bH/bGFWnfaVkvsa+j6E8gNVgXeaR9Yv9MIFQUz+Rb0N?= =?utf-8?q?TsiB85AZwiQJ+nZ5cyOq5OCf5LvGWPXu0IG2+9fC50AIFAvavGs2S6H/FpedHYpMT?= =?utf-8?q?xERpyFNgXneT1pI2oRxcpsOh4k6r9kBXucWDZKK5hyBs6sHMY2wqIYj+kdwIaRVWi?= =?utf-8?q?qK7E9OrY6m/7jdXLBKkAXYYNR3/NNYhWD01svMVCrEFxwW3OBKOTo7GBN3g60ttqf?= =?utf-8?q?XrupYXfYmT6frH1P7zMbouwcq2kCM9OHjTRd7KRKcaVXEwiM3VxGZ5uyW7jZ/oBbM?= =?utf-8?q?eI3y0D2mThxuMp?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: ea5ff5c7-5006-4b4b-627c-08d90027004c X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Apr 2021 15:56:15.9685 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: t2jRmwR48ASAwTQjEYAdYhTf7Ot6ObSJO2Q1hXxnxZqLyaGsL7M0IVFJIzGzMiwET/iEJLpr46i+wBgRfHkuBg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2766 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Brijesh Singh KVM hypercall framework relies on alternative framework to patch the VMCALL -> VMMCALL on AMD platform. If a hypercall is made before apply_alternative() is called then it defaults to VMCALL. The approach works fine on non SEV guest. A VMCALL would causes #UD, and hypervisor will be able to decode the instruction and do the right things. But when SEV is active, guest memory is encrypted with guest key and hypervisor will not be able to decode the instruction bytes. Add SEV specific hypercall3, it unconditionally uses VMMCALL. The hypercall will be used by the SEV guest to notify encrypted pages to the hypervisor. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Paolo Bonzini Cc: Joerg Roedel Cc: Borislav Petkov Cc: Tom Lendacky Cc: x86@kernel.org Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org Reviewed-by: Steve Rutherford Reviewed-by: Venu Busireddy Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra --- arch/x86/include/asm/kvm_para.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arch/x86/include/asm/kvm_para.h b/arch/x86/include/asm/kvm_para.h index 338119852512..bc1b11d057fc 100644 --- a/arch/x86/include/asm/kvm_para.h +++ b/arch/x86/include/asm/kvm_para.h @@ -85,6 +85,18 @@ static inline long kvm_hypercall4(unsigned int nr, unsigned long p1, return ret; } +static inline long kvm_sev_hypercall3(unsigned int nr, unsigned long p1, + unsigned long p2, unsigned long p3) +{ + long ret; + + asm volatile("vmmcall" + : "=a"(ret) + : "a"(nr), "b"(p1), "c"(p2), "d"(p3) + : "memory"); + return ret; +} + #ifdef CONFIG_KVM_GUEST bool kvm_para_available(void); unsigned int kvm_arch_para_features(void);