From patchwork Fri Mar 29 22:58:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13611219 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 28BE8C6FD1F for ; Fri, 29 Mar 2024 23:05:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B54446B00AE; Fri, 29 Mar 2024 19:05:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B041D6B00AF; Fri, 29 Mar 2024 19:05:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9A5056B00B0; Fri, 29 Mar 2024 19:05:03 -0400 (EDT) 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 794086B00AE for ; Fri, 29 Mar 2024 19:05:03 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 49CCF8062E for ; Fri, 29 Mar 2024 23:05:03 +0000 (UTC) X-FDA: 81951608886.09.AC89038 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2044.outbound.protection.outlook.com [40.107.92.44]) by imf30.hostedemail.com (Postfix) with ESMTP id 7E9198001A for ; Fri, 29 Mar 2024 23:05:00 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=Xka1XG2f; spf=pass (imf30.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.92.44 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711753500; 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=UKXbCNmvSryiI54Ff2uhgakSQGjXdl1kQVmeOpa0KZ8=; b=F5ZxNfYpBrCyuENHoDERBigolxJsCOes7rVFTpFr4B1O+YgM/za9WpbQNK5rLWx7XYCl9k xmekXworoQaDO716kbyOkSAd+z8+vvRutHaNZjlC38dBobhaWpMkCeM/quJsp2IFG4oGa9 2HlNQiM005vodkVcJErBvzwtvjA4zTc= ARC-Authentication-Results: i=2; imf30.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=Xka1XG2f; spf=pass (imf30.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.92.44 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1711753500; a=rsa-sha256; cv=pass; b=69GcdUVrQ0BsTf2hA9nbEMbA7YlY+mxjT1ajp67ANHv4TpzMBd/bN7AhCm/+YBDeSLFO32 zh9lIjWjmpzKv8YSQP/guVqaBvShFdcyMtSBFJD2nOEewi/yMdUwnWZZqJAKi1obZfDWiP /HeBpjhyqlXKh9LiIqOpPS4zKWE+rlo= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FXDibqk7audhSslyrWUhdymjwMsQlEzMG2y/x78y4xNKpoWOo827VJQzXPgB3c+qB00rBZuD+8AQtEw0y1+NAzeNqkxzyO7DRwb4F1yRvyPefna1MvPImOQkZ17YR6WNDIhBaNuMNIS13W+1fL92yZYZ6p8uDGRFTaVA7XDEDDtmgmTCVhILSOSJe0pfrm1f/omU/b0E0zuFV7qwxDHnWGDQofNvNc5i7d8fxmK6uRx0jFCCFQBuay9NHyxgKEbr8lXs+wFwHa0qmtCqOYG3PRcK0zObwfpfRkLCEotarKQBLEJpyEiLLpPr938eHuWUkPEu2o93zgUP+kHDWfTD2w== 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=UKXbCNmvSryiI54Ff2uhgakSQGjXdl1kQVmeOpa0KZ8=; b=AC5zoY6d1lkApRPa1lIA34CEkDj1miK+dFwOns8Q9zQ4nFidEm8q2F9JaRWdPI4Sm6tcwUSySd3EbwxtztfjS8ZeF3TWaPICfB8Quq7U2mrYk/SZMGjZAz2S/4bJZvyagyWcrxpmf9jFUspVS8WIlmMnntHVrsIDoDQFBBqqSVU+vyN5L5l8VGkO44d8pETQ8FKLc+aEjvHgfHQ3PaX/7PyDT26nt4eiMw7g3nO+BaWX3ThTadRApqjTHubmUetlZ84kaBJygalxokWYcH/lzSJpTE6kzsTCznSrGag21iDcbxvQDwFA5RnpAG+GQ3RxU2CQO1EZVgHdX2/N9uO1pw== 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=UKXbCNmvSryiI54Ff2uhgakSQGjXdl1kQVmeOpa0KZ8=; b=Xka1XG2fkRmyPtKz/8goE2vk8Rk5bg/mxX0s/WDaYPg1sDtMIDy5CC0XgY6CIBAL8tWodrDXP53P9LWeu8fDhqzVP37LGNZscib0/nqdVZjR1d11l1QmnEyHWfsrzL/ghq4KdZWatmwndh1wz029ZTn1PXi3gzHvNK4MQ0y4Zbo= Received: from DS7PR05CA0099.namprd05.prod.outlook.com (2603:10b6:8:56::20) by DS0PR12MB8019.namprd12.prod.outlook.com (2603:10b6:8:14e::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.38; Fri, 29 Mar 2024 23:04:57 +0000 Received: from DS1PEPF0001708E.namprd03.prod.outlook.com (2603:10b6:8:56:cafe::78) by DS7PR05CA0099.outlook.office365.com (2603:10b6:8:56::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.17 via Frontend Transport; Fri, 29 Mar 2024 23:04:57 +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 DS1PEPF0001708E.mail.protection.outlook.com (10.167.17.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Fri, 29 Mar 2024 23:04:57 +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; Fri, 29 Mar 2024 18:04:56 -0500 From: Michael Roth To: CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v12 24/29] KVM: SEV: Avoid WBINVD for HVA-based MMU notifications for SNP Date: Fri, 29 Mar 2024 17:58:30 -0500 Message-ID: <20240329225835.400662-25-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240329225835.400662-1-michael.roth@amd.com> References: <20240329225835.400662-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: DS1PEPF0001708E:EE_|DS0PR12MB8019:EE_ X-MS-Office365-Filtering-Correlation-Id: 1cb76b00-24f6-4909-fd0f-08dc5044a78d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yFOatBafXFkhfpYHUPmHZDL/5eabrCO0ABgx42kViRZOnMzg/BXECy3vh/VjAzJGuLMX0beyXKLfFnpVS/TpumRl/K/DpcTj7D+zhJrRsxIWQL6pkQcb3bJZFjHMcRah3wrMaaUP8l9oFVhLXnH/U5zfJHYxQGhrROf7qhSrIoZWt+A/TnZ+uNhOU0kjOP1Rb49edFVRyv8tltUrSfzs4AgDbgNKAI1FS9MWwFOmnUgdch6OObRiTzIz3GeCnOh9d6ap0HyWq2nZbm5R4YCHm2/uHpe9GB3sWnrqkbG9csxDlVfaAAVzME6l8/nHVPnK3GJB9m+2f2xUB0J+iJme0xxVycewahL5pOj8Zk6knIPS5NosPZJJFURpTSOeCbqWwN29zyAmYjy6b0xk5cUyFpitD5oVE5tp4RFdibQlDuUL4Na2hiIN23DzDEKlLhLCs8CME4B5GofrN87PZefnO67iJDl6smC2mC4NGdsdW/sLbp/OVkCHY5ZtqRDmq2b+U/gvpw5BDZ6STWD69bMKPvjYF1yXq4UPQmm9jMWIdzhKF+PY212DBX/tIYeQgy8H08ra6aCOVvmiQ+wsv7HnZo37qtMcbWZKPcOWQAq/ZTGxaE+c9xP9OB8oaLEoJsetF6W7CmwX5l1c8pvs9l4AMajJnf9Gone6DhYnOLAWk6/26TZpdy1sULtZClaq8YL6oz5sZkL4Ix+lh31M/W1Jmee8WYkF2UvDCQYEMLpyiC4jYAbiw+0LskdNQ4PI9JR1 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)(1800799015)(7416005)(82310400014)(376005)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Mar 2024 23:04:57.8085 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1cb76b00-24f6-4909-fd0f-08dc5044a78d 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: DS1PEPF0001708E.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB8019 X-Rspamd-Queue-Id: 7E9198001A X-Rspam-User: X-Stat-Signature: 1fx46i94oaj1j8uoizdruujisuoumybo X-Rspamd-Server: rspam01 X-HE-Tag: 1711753500-287879 X-HE-Meta: U2FsdGVkX1/Yl8bPQfEQAxSVaeRhbkpJhjA8zOjnODBlxUkWj4Cp0UCa8DK8sNO8ummfAyq7Cte3NxOOym+R9+MDyziZOdeQBqzv0pRehx5T3UGy20j2SGKelSZA4yhFVGv0uU2dew0gRE8bxJDqhlpoA+2pYLNeYwawLwzj9/nvRepgnZXvZ7O6UXL2zyJPiPKFB/kz2h+RXfELr6StOtf5oj3m8L949cxacDTWbiKFnIva2OlMv70y2PaBQ/lc8jd5VG/7J1FqWCMtoiw9N8YGn4GXHZzCEO3iVdVR2THx28pkUikzEP72wu79vRjGji1owYSFATKB8I3PxS5w0JxPJKXWMx/3nI8Jpq+1UPdncoLjnhGFrzKEmIwdVO0Hx31/X85bFsnMxEqf+yTjsZUZxopB2CW0hbdHeLWSeReIaNXJ/daPtwSae7Hl1QRQ763kp28qgoMjhvmrM/3zPzdVwktg68ybgr+Jf3lUQlV5bMktWLM1vrAKGcICGQUc/v2tyXyXVtVDaadITyJzZrNG0+Wa39QVrOtOCMbYLUlO4w+EnIaQaPafLLBjAQYasvx75N8/Tm5M48IF4Ekd/uSIXIsSV3Lfr5ds6BktJTnExO9q7gKVE5zhyHhalWNH/7tX9/1aEq+Q8XEC5TMzcOTwy9zYgkY+5/p7ocCnUfSM7ieMAGEUcTmJfCzyTFc0qUCeQDRhXtlyHhUhQGQGd6pP71ejuNq1sOKA1J5xm1/DgOJbQp80oN/T84JvwM5QKZl0dY1kRDRkb/7h7DgiXcmXlqE1IZMQ+ipKPbqTizpANTRyBk6lLq2JLdMBjth0Ad7FDD8AGpTJjiNMIsfYhrA+IgonP81SC76lKmTce5/GEdy8/TG0o1uzySLZHCj02rk4kRFPNYK2KfzPUk7s/OnsSAcBTCq1UDOYdvcyRnRahnlwiFE7fYcRCSti1JyK97rHq/ak6XBdmi6MQUi qiA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, 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 [mdr: Add some clarifications in commit] Signed-off-by: Michael Roth Reviewed-by: Paolo Bonzini --- 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 31f6f4786503..3e8de7cb3c89 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -2975,7 +2975,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();