From patchwork Tue Dec 8 22:05:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Kalra, Ashish" X-Patchwork-Id: 11959931 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=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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=unavailable 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 ED62FC4361B for ; Tue, 8 Dec 2020 22:08:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C0C68222B3 for ; Tue, 8 Dec 2020 22:08:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730652AbgLHWHc (ORCPT ); Tue, 8 Dec 2020 17:07:32 -0500 Received: from mail-mw2nam12on2059.outbound.protection.outlook.com ([40.107.244.59]:19552 "EHLO NAM12-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729512AbgLHWHc (ORCPT ); Tue, 8 Dec 2020 17:07:32 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mW4ncGhUc2toQx1V49hUot87fWvOlOKWpItlMXPrACatLFK+1tA8xo2WmI8iQE2VYG1LXNR2q6Xhq0ytxEMYvJOLP1EuDLt8N3q5llZ1WDy3Qtbcc1htaf3T/amiRPWhAn8hR4kxgmElTOp2zhEO1uTcGUKv+bWSeRfEhyLfeYdrfJpmB0nZgYbPkysTouwrTw+KuNmdbvq2nw1b5Rs4WmhZWVqGUzVOkxzjZ5NSd6HdIjR0IRqrD3/6JELtH26OJlPcLlHCneeKdbIVfERM5DuKrUvfRAdo4+o1A2hpRQdNqvkdFROefq+BXPsmgYFDZmmNvisXz/WBIMsyTgFqkQ== 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=djYOIZIAe+UUpzeBZtr/RMxOzG5cL+NruPXwZsscQuI=; b=RlKs6ypQqmb8gkx95LRQ0pwbpueDC800d279T/5riOKrWn9Cr3OjwKN2MU/ix1UWqR1xecURpEB/xr6f0TE5D7iRWOz0y8+RXbG4aBToXTHHh4sFmnarxMVDyMN923D1lMel9lxP9Zzj7DCIJlNC/IoLgaERFO7OmOnONS7MspHJTYgNPJSU2xpeqlZ9XJG5dBBIdkA2PAQYNMJ0KQQvRuCOBHr9iD61NXo6mFZizVj6EqZ06CTLYZsFRTWLQFODIRKqld3Vv5ruNtyaD51U6NpEhoimawYtaeOMSdskgu+6gQCTycFNQwk+JkJlTnWFUi7XfprYEeqqMz64dnbRIg== 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=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=djYOIZIAe+UUpzeBZtr/RMxOzG5cL+NruPXwZsscQuI=; b=BaK70AuuJBIxuywqMB1R77GsKHlgFHq0FThDU+TmNTSIUg5MU9871U8RTQQ/8EIm9EuvkgSAjLWAArDf/q8Ma1F6WivxBIyh8as7z8M0m48ktKDmn2+nUkCNAqauPdsq3Y4PARUW4kLL+QDSeyDUlBPR57qTImKFQwalouwbq1I= 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 SA0PR12MB4415.namprd12.prod.outlook.com (2603:10b6:806:70::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.23; Tue, 8 Dec 2020 22:06:08 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::d8f2:fde4:5e1d:afec]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::d8f2:fde4:5e1d:afec%3]) with mapi id 15.20.3632.021; Tue, 8 Dec 2020 22:06:08 +0000 From: Ashish Kalra To: pbonzini@redhat.com Cc: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, rkrcmar@redhat.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, venu.busireddy@oracle.com, brijesh.singh@amd.com Subject: [PATCH v9 07/18] KVM: x86: Add AMD SEV specific Hypercall3 Date: Tue, 8 Dec 2020 22:05:56 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: CH2PR05CA0032.namprd05.prod.outlook.com (2603:10b6:610::45) 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 CH2PR05CA0032.namprd05.prod.outlook.com (2603:10b6:610::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3654.7 via Frontend Transport; Tue, 8 Dec 2020 22:06:07 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: e384e82f-25bd-49d2-963f-08d89bc57747 X-MS-TrafficTypeDiagnostic: SA0PR12MB4415: 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: ahEtrBOLmqHrXvkQ6npitCAdpB5kQ/lk9XqhRgyOZho+Sb54i83RTDnSRUIZEFA5hg117sVftjdLNJsBWRV7B5/2W8VslO2tU9DunF1ir+swjFqv1LDsPRE6wSBOsvHgf0kx2HDfIRfi3J/V5t6QOsm6mm75ct7xvZvfOMXEAGBujmPHY+5HBdQ32FNvKsNygRMSV7cQY5OobK3haxcj5VYCR28QvLAe/m51thvTCeYwZzFjRU/cOkCalI+eDbTFs6Z18SVEG9O1yBytt3RQ9eZyP5V+UZCngYwBkrJVMa+3kTXCsmCftcDYRlT0bETUpzfgksdQLXU8fmTs7/8MVCZvok6jshD3E3TFlBs3jECAf6PGxvtq84PgjL/K3QVV 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)(346002)(136003)(366004)(34490700003)(186003)(4326008)(86362001)(6916009)(7416002)(16526019)(6486002)(5660300002)(66556008)(8676002)(8936002)(508600001)(7696005)(52116002)(66946007)(956004)(36756003)(2906002)(6666004)(26005)(66476007)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?utf-8?q?vhqHMiswzgVTX0G89BabYjjRBso86u?= =?utf-8?q?IbHxTY3cHBKnp+y5M3BTRq14alfAcI5HLpR9fXQy12kciLpgmBLCDEivTD2AjJhEP?= =?utf-8?q?k8J+fAET1wY241jcFwjQF5cI7mSvMK3zboaHd6qiAfFG32FzrTiswAD6DMPLRdnfZ?= =?utf-8?q?2qKiGXy3xLmFzav0INUSBqSKoWK4eeRCAeT77GfO7Tv2JkOKVd8iobJTQBYmfWpj1?= =?utf-8?q?oGl+f9YvcjEQ9UHo6p2uuQZFmG+fIV0KIQdwLwEFcBYQQZRBk+3XK0S34H34bCWMv?= =?utf-8?q?j9okiIwlYSeTtBjYhUyh9KoF1d9qFULDn0S2g3NV1DMAMMD4zpkdYOaGrKy+aS3D8?= =?utf-8?q?YhR+rcJjrQowFWNBg0d9dCS7mZMeojevadz1COq8q4VIxqymwvsMTHehrD4qt6mMQ?= =?utf-8?q?cSs0U628Yg3xmsnGHJ8B26+PZMYUEqXCzeWr7UklVC3Zj1W24VDf/lL91hfapGZGk?= =?utf-8?q?I1Ketv7DS6ARu4p7iYrTbvKIh01oSlO8ZM5STaqmNyD3CCm1k/vBKhU9oCO0CCtNe?= =?utf-8?q?Y4otrv2YBILDR70ehWhBPHWPngyosHi44ME1Wlm6EP6gn63gNV7mJOIwUa67Z63b8?= =?utf-8?q?gLZauFA75jzT3UN544UQdru3JnzbAgsuSwTLtVrvHWIofQ1/Ds1XnNx7q0kSD5qJ5?= =?utf-8?q?tD3meWgVe1W3D6cd7fB6L6x4b6Imgk+RF91zYXA3lUzX9eY6R1syJvfgtW14vEepy?= =?utf-8?q?iZ/ee1sZeB5tjlXrDzzSWgPvTQ53zObI2COvGYA13F2JtYdf1dQRVsVXKxhX0YwDF?= =?utf-8?q?1dazoQMLgKOO6vrcPgUw3Y910JSWi8h+CwYsovshhGYVgOX90WR1s2bpu5xONI03C?= =?utf-8?q?JbKxHcWRpUN11W8JLCleXEbSWmhlVg/4IzC5ir+80R932NQB/pkUZRTg8qA/Gsofr?= =?utf-8?q?m5I4sd4NQxxeJewfY+EleGGMAD2TWMP/IIEMWgn3UKuBZYSaybZxly2htGDFI0t5j?= =?utf-8?q?xyN2ifW/hrFFhEKFsFT?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Dec 2020 22:06:08.3778 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-Network-Message-Id: e384e82f-25bd-49d2-963f-08d89bc57747 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: iaoetLSuAU/0WX8LQRL2tSzULD2KdsRIUXM4cEaBR0FcYPMcy7xvsPN6rHVYYy5P1pO6n0ZuimbGKW2j0IZ/ag== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4415 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: "Radim Krčmář" 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);