From patchwork Wed Dec 14 19:39:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13073522 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1B5E6C4332F for ; Wed, 14 Dec 2022 20:08:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B14FD8E0020; Wed, 14 Dec 2022 15:08:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AC4E98E0002; Wed, 14 Dec 2022 15:08:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 93F2A8E0020; Wed, 14 Dec 2022 15:08:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 85B5D8E0002 for ; Wed, 14 Dec 2022 15:08:54 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 6A6D7A0977 for ; Wed, 14 Dec 2022 20:08:54 +0000 (UTC) X-FDA: 80242000188.07.6CADFE2 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2050.outbound.protection.outlook.com [40.107.223.50]) by imf26.hostedemail.com (Postfix) with ESMTP id 7B349140013 for ; Wed, 14 Dec 2022 20:08:51 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=uthl4Eu3; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf26.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.223.50 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1671048531; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=SzMxwYpfyh7XFqtLB97O0RIzVpulsDfAAiXFKloaZjM=; b=vsoJyzUj9aRd1EX5AzxZJ/Z415aJpACl3Fnig87fBPaqXpzI0bfeZyTe+OUioxYXRyZ797 U4BM3ifjwMNxT9LoaiYevmIl+XQIrvOOQvudHBLvDddIw2aoG6EPYgHdVNOqApoKSRV1OT cX6fLuapbK3UNYipZY9ijjEKQ0mZs0o= ARC-Authentication-Results: i=2; imf26.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=uthl4Eu3; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf26.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.223.50 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1671048531; a=rsa-sha256; cv=pass; b=pI+LKgEHJS9uVoYkGn41NphIUgGMY08DZO1m/Q6FE5G+FS4DWlD6h5IRKgmuFSV6grs25s pJgofU2R/ym3OqbWFmZdA2vHXVf3aGleuFk35DDhMtREkyh9tCZDjC+M4wrkBOTT2Df/1X nOHj/NWeMuJPwpJ4aFpKiFiN5677OhY= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GphtGA4gOyGS0xHy7Jz9c2jBm211YnRlti0Bjzh6rhVZWFph8cVR0dSnDA+zqwUBu4innzWZYXhzA+3lKDOgREaPdQBCGWm5OU4tPjkvRGtA3R7P6dxmNC12c9IorGa3WSZy5GHqAgUh0iaFrJQr5QVdfvLC5eY2fSyMpjdmPRASCv5VTg4Pbv/9XFhHAYd5/i+WQBqJUwhVgnYK0yyqgU3k8GXWnXglxyiuZYH0OyRnZrV8IXuCSL+ntFu+0/GLHC0o+EWOsnCrd1HjkO/JkRAUM5ZkU68DkfbUUe+v4rS6mGB4d3idsWoS6mJV2ID4gvIRTFkLAdV1NWJOpwbOEA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=SzMxwYpfyh7XFqtLB97O0RIzVpulsDfAAiXFKloaZjM=; b=g9kLDrfaaB+4Ym83OPzEfb0b5PB7y2BjVX+esu98sqvOpd2d2MglXHYc/EhAM19VSJkIyMyHz/kSeZ/ZKZ7dCnnNl/4KB73/U325HEnuYFbpYrhJst9EdWN1KCd8ajEnECQvyCnDXzj7udZPujvWI7DBw7uPG/+uJ724Vjqo2SHPsW8x5NsNt4xJbyUbRDO1kWjglQhVndjZELLR74OSCQ/Kulc1LBquEMy3x0QuqJJ+nNnt9jT1bhdVOqe6XEubE7LLQu7ExikJSJ1ZMeF4KedouRql3qovR/SPMRlyqHd9jT2WNmLbzvbIDh1CZuO3G+sWB9bm/DUbyIUprqRIyQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); 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=SzMxwYpfyh7XFqtLB97O0RIzVpulsDfAAiXFKloaZjM=; b=uthl4Eu3LMMMLNn7XH591fraZvSbUrasyB1sJGFToQAidqp9IldXjkIjnxNMHneb2RLNR33gA6eYDWfXIX8Cmh84nOBsBXlq3vvVNwNZzgGw/1Uz4YR0VmPW2Ve9lf8EneWGpZ/FNXLQFv7vqTsBTqNp80K8/MAub5YTb7T3cW4= Received: from MW4P220CA0009.NAMP220.PROD.OUTLOOK.COM (2603:10b6:303:115::14) by MW4PR12MB7141.namprd12.prod.outlook.com (2603:10b6:303:213::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.19; Wed, 14 Dec 2022 20:08:48 +0000 Received: from CO1NAM11FT028.eop-nam11.prod.protection.outlook.com (2603:10b6:303:115:cafe::14) by MW4P220CA0009.outlook.office365.com (2603:10b6:303:115::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5924.11 via Frontend Transport; Wed, 14 Dec 2022 20:08:48 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT028.mail.protection.outlook.com (10.13.175.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5924.11 via Frontend Transport; Wed, 14 Dec 2022 20:08:48 +0000 Received: from localhost (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Wed, 14 Dec 2022 14:08:47 -0600 From: Michael Roth To: CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Nikunj A Dadhania Subject: [PATCH RFC v7 07/64] KVM: SEV: Handle KVM_HC_MAP_GPA_RANGE hypercall Date: Wed, 14 Dec 2022 13:39:59 -0600 Message-ID: <20221214194056.161492-8-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221214194056.161492-1-michael.roth@amd.com> References: <20221214194056.161492-1-michael.roth@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT028:EE_|MW4PR12MB7141:EE_ X-MS-Office365-Filtering-Correlation-Id: 7789cd11-542a-4e61-74c6-08dade0f0342 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JxE58TbV2E+WNdeUgEh6tyiJlKDbEUSBe77xbaJRTZwknrvt96OxXLiReLBAzTtnFOie/h2pSRT1fpt+DFKuqqwjK7c3FnuzyLAs8IafYkYT6A8HNyt0UsYROuBx+9FnyIUPYBd3adqej8/TRNxGjavVOtOwlCADwPu1xwGCsseTeQjJtonZac5WcEiSKasjZQz3OVbcME4bOsqq9t3oO/2God62VYAG63mEtkjGxZmRmZMDbgb6+AG/0UOAmG5DWBWGjWMjhGZmz03bcYHaky+9EDxcKiNgAz7twCplYUME2r/OR2oE3iyfEtfzBL3Kcsd8jvl9zqBw0bWnPXgGPxvuG1VUCkrDag72qQF7bYqYh9mao9LA13Wvcdw+E+X2f9J9tp9EIXl+092AJVaQ4pxo6qrbgduOHvxOPwczsYcCZpwPEeEhsMjFSpAZmm+fObeUEB3XlBNKCPph+Bo9uONDQp2xsmj0MiCEyTdqtJwIHr9OYCugyMH4niK7NAmgEtW1W1vpKWHozbO9WIxzI/McW6/b3qAyJurowjy5F47yLIH8XX0CUupUt6NKy1oPragHITkRahcNC49yna8p2H9ipoPJvDic5LEU4oFl8MUOC0BrgEdIRkOsSZ9Z3nIhDVJsoc5/9JnIIyyOiZEVEHok6N5jS2kn9wBm/XaLks0te3qsTQ40Pw5aBAPBmRIngVkWb6uB70Smx2VUiowybJaQqX40lBAQHilMMQH6Hds= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:CA;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(136003)(376002)(396003)(346002)(39860400002)(451199015)(36840700001)(40470700004)(46966006)(8936002)(6916009)(5660300002)(70586007)(70206006)(316002)(8676002)(6666004)(7406005)(7416002)(54906003)(41300700001)(36860700001)(26005)(36756003)(86362001)(82310400005)(4326008)(2616005)(336012)(16526019)(426003)(40460700003)(186003)(478600001)(47076005)(1076003)(2906002)(356005)(81166007)(44832011)(82740400003)(40480700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Dec 2022 20:08:48.5346 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7789cd11-542a-4e61-74c6-08dade0f0342 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT028.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7141 X-Rspamd-Queue-Id: 7B349140013 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: mc1uwo9argncduhs1ts9t7bx5qhc3um8 X-HE-Tag: 1671048531-33937 X-HE-Meta: U2FsdGVkX1+CqEvMxs40X8CZB/AquYw9NM5rDSVRbyJ0Dxvpd1t1iV77Z1hPd7woyUJllBlLzsOlVi/TTkplxvkIZavbLudLrg8lkTDC4+KtRs5cldrXvqUNPYt/Q0Sy1IJIvDdBlai455KXP7B1fQnburknHfMA8xf85/E049qu+JRtSpXSHyugMGnFz3fP3eXcIH+gOV2pCUHhT8nrFfU44QlgG3mGL8X0wscbnDystHXL0onAeP3yRy01VDlJK/09v9hmqXyRfi73WGN+HtztiEyYqHakwQLEeftnPZvvHtapmCsONci2jLiZq1dnXFQJTa08TE1ZFB6GDQF5vy2jaUR2/8WanzVtitLlyRl7FU+C0X/VWohDrbtH3GWNmmHqluZlrgUHZ47iaXboZmna5Md9/ZDhfi61sFs7aAWRg2zm0dol/gmSoqMzCMc9LEmvqIhW305BKc0jgmODmkU5GZdL6UsuSzdiwVws8qrpuVdUscGd83XiHwrsznPcLWgBcgpnqno13RQyXtXvGeGvdxzSq8Jfk8Fcmy/+iChvml+l9XRxMuY5hIhPzXOEfFirUBdz+BJ+keFOiZjGfgddUATUyeIXJAaJbvqHBldpXTnoLxF7VIsXsnaUZglZsNKyos1Li0kImt7sNgySQCrpLig1H2LXv6WR5Iz+YyjeF9b2haUdbdaWwAFZ0OLwfK0f//6z/sfv795XwKmD8l2ogpJLHnX+zZkykllFGjSjXJXrJw3ompLIS0TlX59CCewW2/2gj68yBPYC6ruQ9rSYZgaoVvZqo45vw+yk1eLewW/xZmgKYa5YUhFkUFXk62GpFD7zA7gHNxn3JL4DpqR+wQ7IACc+hjKt5LFsU00JN9cJExPGiMBNkS2fffQ2Bh4XLxejlS86qhn55w+eh2sn4OPSMOEzM0yzpv4DxlcUzpp10ZZpbTaHP+35f7+A1xUP+zs4deyVLUtLVj0 +KSw8WLO snCsQ4xnEBoNKcqk34WagnD/bAzj9W4xPRw6fL5zh8ltGMlDK2iHYymreVA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Nikunj A Dadhania KVM_HC_MAP_GPA_RANGE hypercall is used by the SEV guest to notify a change in the page encryption status to the hypervisor. The hypercall exits to userspace with KVM_EXIT_HYPERCALL exit code, currently this is used for explicit memory conversion between shared/private for memfd based private memory. Signed-off-by: Nikunj A Dadhania Signed-off-by: Michael Roth --- arch/x86/kvm/x86.c | 8 ++++++++ virt/kvm/kvm_main.c | 1 + 2 files changed, 9 insertions(+) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index bb6adb216054..732f9cbbadb5 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -9649,6 +9649,7 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu) break; case KVM_HC_MAP_GPA_RANGE: { u64 gpa = a0, npages = a1, attrs = a2; + struct kvm_memory_slot *slot; ret = -KVM_ENOSYS; if (!(vcpu->kvm->arch.hypercall_exit_enabled & (1 << KVM_HC_MAP_GPA_RANGE))) @@ -9660,6 +9661,13 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu) break; } + slot = kvm_vcpu_gfn_to_memslot(vcpu, gpa_to_gfn(gpa)); + if (!vcpu->kvm->arch.upm_mode || + !kvm_slot_can_be_private(slot)) { + ret = 0; + break; + } + vcpu->run->exit_reason = KVM_EXIT_HYPERCALL; vcpu->run->hypercall.nr = KVM_HC_MAP_GPA_RANGE; vcpu->run->hypercall.args[0] = gpa; diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index d2daa049e94a..73bf0bdedb59 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -2646,6 +2646,7 @@ struct kvm_memory_slot *kvm_vcpu_gfn_to_memslot(struct kvm_vcpu *vcpu, gfn_t gfn return NULL; } +EXPORT_SYMBOL_GPL(kvm_vcpu_gfn_to_memslot); bool kvm_is_visible_gfn(struct kvm *kvm, gfn_t gfn) {