From patchwork Thu Apr 18 19:41:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13635351 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 DE5B6C04FF8 for ; Thu, 18 Apr 2024 19:47:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 71C086B00B2; Thu, 18 Apr 2024 15:47:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6CCF76B00B3; Thu, 18 Apr 2024 15:47:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 594126B00B4; Thu, 18 Apr 2024 15:47:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 3C4646B00B2 for ; Thu, 18 Apr 2024 15:47:23 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id E3DCC410B9 for ; Thu, 18 Apr 2024 19:47:22 +0000 (UTC) X-FDA: 82023686724.20.020E519 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2044.outbound.protection.outlook.com [40.107.244.44]) by imf09.hostedemail.com (Postfix) with ESMTP id 056C7140014 for ; Thu, 18 Apr 2024 19:47:19 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=RsnOAaYG; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf09.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.244.44 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713469640; 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=sP0j7CgSEycNQ9rKRi6PZbBr7samEL54FEHOW51Nf1c=; b=uQuS/buWtM2QsIUjjRdsm3VgY40M5qTxDaF0fUcGE4UV4SgUYHnKZ0nqK9NxKkeKTEEBLh A7XVEtKmtQmS66HriUP9vTPguVd3YJE+4W0QTlaPQAvsWaVDfN65MiIOzXUzkeosYm5ejl WlvE/pghTIU1dhzcoNJBLIhDoeK+EOE= ARC-Authentication-Results: i=2; imf09.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=RsnOAaYG; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf09.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.244.44 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1713469640; a=rsa-sha256; cv=pass; b=d51ptO3DtnySMiH4IaQTs7eDiT0tUQbAo0IE4Hkvte8JsK0GO8aNSV4kXlKBmQ3/7szqV2 ZdbqtKwVI1oq+0f6qghHSoP8tbWNXq9rDQYPSAo2BIaTHZZW+N47ojDEBDy1u+3XwBg5r0 gPWcM1dfzkdT7Q9gexOTKpNhA24HExk= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A8DMoESL7lG54guWjNPgl/t6RpxVbpPbH1cyjBT5eLfPUufcvmlKYzBL1LA84oMFtkRomF9WkHBRPK9AqbCFn7g9cAdAjaxWZMn/YhQICuWJZrOALK8khT/eYSQ0KHd+c4APWmsElLfgO9Me5h39ZP/5PAhzpTZhXQGRJLuZWRcfkxDqmeS8TAwhMIhHYUUeR84F996uBqgF+uJTOSOQT9AH01AJlK5DIGNJy4dONBSmiRmBNqoR6fYRj2/k8irEInujqqfPchoGl9T6ZuFoITE8WPe5zAxxWii6Ts9zN5QwSxhUpps0tvPsjUBcd/gt9R4xHRiqhtye2sk5dnIbPA== 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=sP0j7CgSEycNQ9rKRi6PZbBr7samEL54FEHOW51Nf1c=; b=KBnfW2RrQULaYPeSTKaONCJl4bCXdwhTtCOeVGC886g8P8EbM7mE47VmaOTDJWkx+PJG1Gq5Bwuz3koOl+gC28m9lNFgsM1Zfv3Rki3Q/HeQ1af33IgynAWUsUH4t8g+BSUYn5+ZBkGhlpAVNVE7oW8Qv2gfUoPDDRmnzaG9SgzrZdp6wc2tnPKH+1mBB93AmExrvdbvwQIL/eARPJIQPaVwKP0hQuVeIuBuZvhc+wVSemKFQYorsImCMAXwzvOxNOM8Cg+LKAHtXknlVgzSif7BSl1vXw3Mca4NMm1hta07uEby0966IgAHXxs+dCfzhAtNkO/2aJLZhdt2vPucKA== 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 (0) 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=sP0j7CgSEycNQ9rKRi6PZbBr7samEL54FEHOW51Nf1c=; b=RsnOAaYGgiHRCEIp2HuaihFHivj7RPtSObuDRKVu6XAK/Eyt6zMIttA9ENrReyG+lCGlV1NoRv02y1bTqTyc2emGbm7fu8OvV1b92kNY5U4ta/lOwGzK9yBPZsPn3uoiWYIeg6yJY4fJoyxQYn9d1M2da/M4s9Sfoo1TunG+ewo= Received: from PH7PR17CA0038.namprd17.prod.outlook.com (2603:10b6:510:323::17) by SJ2PR12MB9238.namprd12.prod.outlook.com (2603:10b6:a03:55d::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.37; Thu, 18 Apr 2024 19:47:11 +0000 Received: from SN1PEPF0002BA4F.namprd03.prod.outlook.com (2603:10b6:510:323:cafe::3) by PH7PR17CA0038.outlook.office365.com (2603:10b6:510:323::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7495.27 via Frontend Transport; Thu, 18 Apr 2024 19:47:10 +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 SN1PEPF0002BA4F.mail.protection.outlook.com (10.167.242.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7452.22 via Frontend Transport; Thu, 18 Apr 2024 19:47:10 +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.2507.35; Thu, 18 Apr 2024 14:47:06 -0500 From: Michael Roth To: CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v13 21/26] KVM: SEV: Avoid WBINVD for HVA-based MMU notifications for SNP Date: Thu, 18 Apr 2024 14:41:28 -0500 Message-ID: <20240418194133.1452059-22-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240418194133.1452059-1-michael.roth@amd.com> References: <20240418194133.1452059-1-michael.roth@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002BA4F:EE_|SJ2PR12MB9238:EE_ X-MS-Office365-Filtering-Correlation-Id: f06bddd6-996f-451a-6a08-08dc5fe0565b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VkWmjpv+jUDPWk7ngZIrgpcynRGPHazvM6y2mADcZYpZYHkW3hKWYn1GzMKtRl2SnwJcVR8PalgJTsgwf+C+MCnDEbSwIm7SE6RhdAyqxbAUX9Ig5oWfj1YxnUXVxop5/mfQP6fJQ+HoM0DHiOtPv3pNmpmYb+bCOWp0ku5vVuv+wRPWad+uZhVoZO65Duk4CkE924ZmyuXkznz9osZ0nsZ/eIGreXYkARSpsV4mmYVM6j6yOxZbaZyBlF50gLY/dfaPdaQeRT2EYmdLZdXwYdYvUY0VFsAWMRm8av2JVLbY2oELuxI1u9FoaRIpbwg1W8ujfsuicGeMY5SwiK7LToJvb5JlE8+Z2Smieh1SSMZw5C4luQNUUgpp3ateT3Qu3yuBkdfwrKnEMzMmorQVVQSWrhMdCJ3K8pRaeZrlx4Rz1NQTXhJGsXW0bzOdNZs3cpJOd6oiF/HmvRoKVG0vRleY+V/Rfpdy5aYd0px6EqWTiSu7mCTQIsIBN03S402VsM984BBa1zcZGURbTCylYga/cuARUHWf54Jo8p5H0bXonkca2Sa8jGCP1Ji4daUVvKFuu4QK87r75/WC4xibzmBTy/PU/f5EyY9rLMvsR+aOdeEqU7HeR6H+QwlSPfYOlg8pXTWpgdAr5NAnB2OdCODtUNv47nVtbEnbXB0a4eEi5mERrgAZrER5z0L2sBKSl5K7WxT4GUiorl7Did3IW5YZwUFjqbPHsIzszIif8axLau/dYbKC1BM7dkrx24X3 X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(7416005)(36860700004)(376005)(1800799015)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Apr 2024 19:47:10.5287 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f06bddd6-996f-451a-6a08-08dc5fe0565b 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: SN1PEPF0002BA4F.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB9238 X-Rspam-User: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 056C7140014 X-Stat-Signature: 74ju6ia3iqpypzyboufqiyb3ki3adgpb X-HE-Tag: 1713469639-36177 X-HE-Meta: U2FsdGVkX1/TBe99mQvjPQChuCg9Eyr3UYknW7qCrKZxhVO8ejWrco4fpWYnJLxNTDU+tryyAO1J8vh4zax4AL4V7SiJ8j2gBu7WxzlJEeHG2voHajcnf0r/67sI1+nqDDVXnVjoRxGsASMOIB6JjeRCoBVmTTPyL5DwAE9LqAYo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MCHMUXWlJNKZvLM8pJ184jPOLGWbPgQ9awKrXW6HRaibgHEPonR7mtpQQB4vFRikSQ99LVEPp5O1vUClDk8fj5jGnot4q9U= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000097, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Ashish Kalra With SNP/guest_memfd, private/encrypted memory should not be mappable, and MMU notifications for HVA-mapped memory will only be relevant to unencrypted guest memory. Therefore, the rationale behind issuing a wbinvd_on_all_cpus() in sev_guest_memory_reclaimed() should not apply for SNP guests and can be ignored. Signed-off-by: Ashish Kalra Reviewed-by: Paolo Bonzini [mdr: Add some clarifications in commit] Signed-off-by: Michael Roth --- arch/x86/kvm/svm/sev.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 3fabd1ee718f..03bfb7b9732d 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -3033,7 +3033,14 @@ static void sev_flush_encrypted_page(struct kvm_vcpu *vcpu, void *va) void sev_guest_memory_reclaimed(struct kvm *kvm) { - if (!sev_guest(kvm)) + /* + * With SNP+gmem, private/encrypted memory should be + * unreachable via the hva-based mmu notifiers. Additionally, + * for shared->private translations, H/W coherency will ensure + * first guest access to the page would clear out any existing + * dirty copies of that cacheline. + */ + if (!sev_guest(kvm) || sev_snp_guest(kvm)) return; wbinvd_on_all_cpus();