Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4056974pxu; Mon, 30 Nov 2020 16:50:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJxsaVIdsNpRNUBI/hsOGonD76MnoOrI1ayF75si0VjSmfAbCHAqyX86GphfL6L/ZNcgr9o9 X-Received: by 2002:a05:6402:17b0:: with SMTP id j16mr464860edy.114.1606783825020; Mon, 30 Nov 2020 16:50:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1606783825; cv=pass; d=google.com; s=arc-20160816; b=0Kh2MLxxWEL01S9nFspHYt4AYsMfk+5VADDlKY3YAVU1ApoahE4+tNFahMz5Vwk9op ejzPJRFlfEqW8k7/EZNrCNpch1SK9UYZ10ICkTOrLw1gRY6tj05assOOX1I0IjF+zXjP dkCytVn3igws3WwaWjNnH1K/RvUA/WrHKqIBmA4naPC9WUhQDEVr9SFT+YF7mD2/EdTp 7cpKlxmaf93yu1GjH/tVIEkqm/wpD4JI3Y27U5cUjoTq5Td1naNZ3fNYG7OhnipR7erV fFIVWKSGSuFHVSwsPo28+0sbsMVrALBINHPxenMdADrXAbdOf0hJYTiPS7uXdSccfawi owwg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=djYOIZIAe+UUpzeBZtr/RMxOzG5cL+NruPXwZsscQuI=; b=rVj/YBSRXPrgCELhaBZe0UezmkEmZx5epyH18gPNOgF68vj5CmdI3O0M4qzZyab+oJ alzP+tNDJWHBxrOTSxEOa0cKeYqs/ZtWrtsFqD4SzUS3dgGa4ezPulh/ldnd5xJQ0rHn Qk10j3KNKtlrDp4xTCE30Fju6gtaLeY02Hu6vZW534JFDm0eDGgqqwemMlmUBoGV1SMB DKnRzGtn1w0Q30eo5CwNtqR50kQMGxdZvswfmHSpbYCThzNKs/I5lJ4Y7KVh4sXD4X3F qin0+67Efda31y/PVtmKyaGkKpbZfry7c7dtEUnbLzIrZhpf2m41OB3rgTtZr+b+WhFB SqYA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=ACpLDEq+; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=amd.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cz9si104241edb.289.2020.11.30.16.50.01; Mon, 30 Nov 2020 16:50:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=ACpLDEq+; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730953AbgLAArJ (ORCPT + 99 others); Mon, 30 Nov 2020 19:47:09 -0500 Received: from mail-bn8nam12on2071.outbound.protection.outlook.com ([40.107.237.71]:20033 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726316AbgLAArI (ORCPT ); Mon, 30 Nov 2020 19:47:08 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QAdQ4wqLarmUB/jtW4hu4fAn/yoPMUCSAPguKo2pQbM0Am2X7TPykhPY+57gvZRYvxP+qsbBCYIxCSPraqYoe321bR2THIiK58bzLHsbXZ/mD3xebV/mQyQCljs5Ex5OC0SEiEW85dzgLywtH5DD+vP0fHHVuqpv8OB0h4+j/+yRx4U7vy+jPJYIRYF/Uv6xX6Zd5+L605va3VKasTYUm66TH5q2hCfeXURll+3m72EnBBe60qceGiLzrsSjWhJEaOmZWF7xET897DValooavUJTArC0S/Id7MkJQqqiFV/FvyWYVhIfIEZiEGatnuQ6b68y3tAhVpIAF7Zpl8i2oA== 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=Sh1wW+KUQpAU0eOUUEo9DGxv066uQJ1i7ne8mAxPl3UNLMvaPpqvgZJ+zj92B3FjWH2YWsZVOBOQoz0nP8jrDYVGXKLE2JJg6r85N0ccIlkJOr/37iIOml8EPcrPjOxR0PxPeBnBfZ8byI8Cqi1e8h8pLC4FZfUi9ZvmjOfWUSXO3koCm9THKa3qclvUsIuB0huLtNdBr2MIfJxY16+iHJonpOSQttejG24WH3mireQSo2sEkouPZrjrP7Dt5wmBvPcL9O6FzpBqh4gSOWvsTPYDQPCUf47gYKeuNVFnyFKxuYf6BR83j8SAYrH502S+5mdlvxtoLu62F6BBsm4vfA== 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=ACpLDEq+C++jhDTgzdp2Dldz5hJ5VJClvuC1ylXbZ9yejnW9olbiFpnVccgLCXO+FRi9kQymfSlFZAxZLV+Hq0THEt1f9r09en9TYsAhlkizZQmbYhD3YSLLlxDoRA0yPM1bkOx2A+J1SpjPlxHoKSTWADn/W3za6mQbQdvx0h8= 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 SA0PR12MB4573.namprd12.prod.outlook.com (2603:10b6:806:9c::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.22; Tue, 1 Dec 2020 00:46:14 +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.3611.025; Tue, 1 Dec 2020 00:46:14 +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, brijesh.singh@amd.com, dovmurik@linux.vnet.ibm.com, tobin@ibm.com, jejb@linux.ibm.com, frankeh@us.ibm.com, dgilbert@redhat.com Subject: [PATCH v2 1/9] KVM: x86: Add AMD SEV specific Hypercall3 Date: Tue, 1 Dec 2020 00:45:35 +0000 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: DS7PR03CA0097.namprd03.prod.outlook.com (2603:10b6:5:3b7::12) 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 DS7PR03CA0097.namprd03.prod.outlook.com (2603:10b6:5:3b7::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3611.26 via Frontend Transport; Tue, 1 Dec 2020 00:46:13 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: b89d85f9-4c4d-45fa-8986-08d89592818e X-MS-TrafficTypeDiagnostic: SA0PR12MB4573: 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: M+8tDGhh/qisGQzsVHvLuLkCd9GVg8ycvrmtM0HoUZwLTHx2TMjSJPvXtusS3dbTnQ/RjbmX5XcT8PRZOE3eJ/I4F/E3hH2L5QFjC+Z9tx6biQ3mc93b+mHWEZT4Nb9WWOjvji4rW6inj8qWUPSWh0EEayb8LI9JyNQyuzc273il+x4soOB2l91FmTL8WXF7eBQIZouiITvyDo6unbZ0oRGyVL9GG8V0SAUzgBmVRkEwQmLzNpBGxLRk46Wb1ca3Llk3W/jg2VLd5y6tVqFPr0ToDTCb7R8vMlWJFWMqaELNY0uIjMoTwHFpH+/NnzuBwexEx3oveHmVT27M0llw4A== 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)(366004)(346002)(376002)(136003)(396003)(39860400002)(478600001)(6486002)(7696005)(316002)(4326008)(956004)(6666004)(8676002)(186003)(16526019)(8936002)(52116002)(66946007)(5660300002)(7416002)(2616005)(86362001)(26005)(2906002)(36756003)(66556008)(6916009)(66476007);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FXVXZxTis5MW9pSDBFdzdyc3QrUnBxSjJ6ZDh2TjVqd09ZYUxmSWx1?= =?utf-8?B?Z040bVVaNmxmcFVja2tuVUhkY042V0ZsaEJqekM4SjlFSk1iN1BBdHF0UUNC?= =?utf-8?B?bUcybGpKR2prdEplYVZlV1IrenhCblRsbDFHc28yN0lWUHdwcjFka1hEZEk1?= =?utf-8?B?S0R5bllsK3BtbjlGSVN0NkZ5Y2xuc3lpbkNUaU43TVVIS1NJdlVqY1FRQSs3?= =?utf-8?B?emRjM1ZiM0RoRnIvdUY0aUhhSDdxRTJOeXhpelhiVjFDN1VtQUdOZE1ET25F?= =?utf-8?B?OWZLTkd6d1RTSHlPMlBVTjhQZGZtaDVwZUpqbEhJbmRDQXFKOURieVpXOXZL?= =?utf-8?B?QmpLUDhuRDZtaUVFZnZwTDVnOGZpN0J3T3YxdnU5V25QRDE2NkFmN2VUalVy?= =?utf-8?B?a0o4cnpoQlhpMXpKRTl4bWFrOGxQWW0zNUZOcitsbnZ5OWFxMzhDa05PT08z?= =?utf-8?Q?qzfgE1BhObFBua10h9LOVEsI2JPHHmLZ3/?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: b89d85f9-4c4d-45fa-8986-08d89592818e X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2020 00:46:14.5910 (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: PVWFKuADWpkSrv7Xba8xSEOA9Cix+/6Q7ELMttiaS/3GYG64dARwPt5kh5Cn+vXbQwx0ISuRpSWFudmVtbie1Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4573 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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); -- 2.17.1