From patchwork Thu Dec 12 06:36:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13904715 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 B95EEE7717F for ; Thu, 12 Dec 2024 06:37:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3E3D16B0083; Thu, 12 Dec 2024 01:37:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 392AF6B0085; Thu, 12 Dec 2024 01:37:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 20BE86B0088; Thu, 12 Dec 2024 01:37:49 -0500 (EST) 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 0336D6B0083 for ; Thu, 12 Dec 2024 01:37:48 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 73FCAC0AB4 for ; Thu, 12 Dec 2024 06:37:48 +0000 (UTC) X-FDA: 82885350828.15.31263FE Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2086.outbound.protection.outlook.com [40.107.102.86]) by imf08.hostedemail.com (Postfix) with ESMTP id 99A36160002 for ; Thu, 12 Dec 2024 06:37:29 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=E9vkbK65; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf08.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.102.86 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1733985443; a=rsa-sha256; cv=pass; b=MZL6BphkDhi1Kw+U16fLnmZb5K6pyxqIs1Kv9njdJ3rUshOIlWq7fEXuLQ4a2aKbg7rmYP 2gbTuuLVMchThOvfJ8gAzKrde/z+LgA5V7mDve9BHwRKzpcz76rzfKUc54EzkPbIfocI/z 1ew7OWiXTEcRvUBnT4CznscDAV+2NyE= ARC-Authentication-Results: i=2; imf08.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=E9vkbK65; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf08.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.102.86 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=1733985443; 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=SEpCbqaP6FQ1j0TWnQ3nVGlIYvGyQD458x1MBo6G7N8=; b=xdLlLz0VrVtk7oaj0k35KxjPW5gCiJCBDxgzKL2LNLV8Bij/GN+LxCHdgkGra43188a0+p b0nVykBl/rTr2lqXK88z04Dq27zGoaorHH+uXgiNYKfRC6DiIdBIMU0IhfyTpVzjBsQ0Hl mh15UUoDpJTUNfGyYmbfRnvbwqTizJU= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=A/nw6CHuS9bWYDtT+GJHTbxL/zdlGYLQQAvdF33I0ux4mwHLpxwglIknZzHhCG1QA1GfIOHfxcAOQ2iZA32uf3MSrPEkS2uYgrs0gk0+qWwpBDcQmKPCdX9lidvEYSjWxlYr07nwRPdQ8tVpgruPNEVqroRGaZEA6+hUyP0PCjfUZIbQnsRExgYZ45hhVYzPzYV6CxI5A2giEQQQvW8qQfEOS5RJ5LqGsS0u8MH+ykVMcQWAX8Ra5muAscmIhytYlL2ZhderYtx1ClErtQR+h1Ni6O5TfDsPvNEbjDl0jIhod/8yh6w06N5z3tCegdiOcXH1SLlpPoyoamXXHdlD+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=SEpCbqaP6FQ1j0TWnQ3nVGlIYvGyQD458x1MBo6G7N8=; b=yCh6md83K+GNaTIAQ/Jitl8GZsT2Lfz7825jGcaWOkoTigZ03zlcXXu0CGwzDUhF3Z351NGvm0T0fnU1xU+8T6wIdxCBEOxIvONF3/QQFVw0xTpLonl1VkPFlFqkxGEJB+g6xYBjtstJfQq/sXQA6CDrYwcHX4wgGqQCMQU1kgUv537QZ/y0hEQQJn/aRi72JehuZSb7IaNXk/uZ1O9WXb+MSglxGYNbrSKCYlzm9QBfsle/j2PLYCSDorNrPNoiXnHkE/b7kt0IKL9DHPLTC295PfXYiqYxgPzg/+t5KKNftfdHQVB7dXof+paTLXjnOrWW2qOMWcTqKmFpJ1XXug== 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=SEpCbqaP6FQ1j0TWnQ3nVGlIYvGyQD458x1MBo6G7N8=; b=E9vkbK651amljcd47a3F6zCVJLJGYZCtn07JzVzfe1eM12F0tIrCCjDzEPnDZ91Bed2FaELbovFhjUsrQK8StDT8ZS8m7zaEnzKWBoGkZtR6uvkAU8IKm+8M8rtIGRkXA/mMX2ZjhJlLRpzITFjqg0Z0c7eZUkSC+yJs7VV9Kqw= Received: from CH0PR03CA0017.namprd03.prod.outlook.com (2603:10b6:610:b0::22) by PH0PR12MB8822.namprd12.prod.outlook.com (2603:10b6:510:28d::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.20; Thu, 12 Dec 2024 06:37:40 +0000 Received: from CH2PEPF000000A0.namprd02.prod.outlook.com (2603:10b6:610:b0:cafe::df) by CH0PR03CA0017.outlook.office365.com (2603:10b6:610:b0::22) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8158.24 via Frontend Transport; Thu, 12 Dec 2024 06:37:39 +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 CH2PEPF000000A0.mail.protection.outlook.com (10.167.244.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8251.15 via Frontend Transport; Thu, 12 Dec 2024 06:37:39 +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.39; Thu, 12 Dec 2024 00:37:38 -0600 From: Michael Roth To: CC: , , , , , , , , , , , , , , , Subject: [PATCH 1/5] KVM: gmem: Don't rely on __kvm_gmem_get_pfn() for preparedness Date: Thu, 12 Dec 2024 00:36:31 -0600 Message-ID: <20241212063635.712877-2-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241212063635.712877-1-michael.roth@amd.com> References: <20241212063635.712877-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: CH2PEPF000000A0:EE_|PH0PR12MB8822:EE_ X-MS-Office365-Filtering-Correlation-Id: 565f4e3d-34e6-4fa7-7255-08dd1a777972 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|376014|82310400026|7416014; X-Microsoft-Antispam-Message-Info: 2LwviWw6veuI0RziRn3eKGsjkbIWG9gjmwK6jYLERg5Qj2NSP58BwE17rZLR8Qv5Q3LiO/gJF6CA72cnQJ+iWvZVZ7unpVDr9/iAZJC8tSGUy7k1dRIpgcOl5IS/nuCTwyM2ESEB9x6uTS3Wd6Jo/8iu5smWEf3f36rtU/HYyIgwKsCTCRwCW/jTb+Z32ed2XI4+ydGJdvoDRwT4zGl1TtLrcRK59RYtocynh3pzbIsvmFKh9yVM93W5U7gzi1fdZCSebJYkpz1WMx+CssOnpFhUiNhbiAy9OUD8uv5m8yblnOYv1G/vYJPnArxbFoS+rJxVdoKm3WdQrP0sQnE1nGFWa5E8L7E5glE3dRneQSplEUdLoegUvEDUXV2YocXIkNmFhlroQgiRJ84m3Agbwjxg1wjmGpY0bR6GcPzHza43fSPp48vhRnfk9bIY+r31nGamBbbwnUcSd1lyDbowPjSHZMG5KH+akf5pWgjPwUnVXRKXuRKY81pAGflaOoQ5Jd1kqtIVMxnDDo06CKQ0lM0u3Q5mEjMDw/1XBc/bjzEOS0nDesY+3iZTxJbdAH5WbId+SY4L5AC0ZXtuzlGMEPADhnzJnwvkfEAbahRcsRROgEv409ZGWNLLqaJvYGdhV+Bt3u8h6/YCKpHrJdKffpX47JZiMJXgh1Je+6T4IQJuZ2PY/XeLyqjd88GxXwm7iczEAStJldjc4WkD3TmXy58h06I8pbbn6yCVGqcIQXnYb0kP0h99wA2+Zp3arbCReuckOSfNbGITtGYHKWjryvVgKq74Zvo5LjHzPBTRLpF+GCi3hXAgewQIm7QGoQCavohdBsV0m1maqmYDj2Vd5cDPfjUX+ZbvbZzgWF6kXNoeWuwZ5x5oN+zz+2JbdjDupuUSp8CWZYtxHSJQDFfQIgo6ai75DOADq+eZHV1INOOri35v0xmv3MQdzvFcRLGpFg9VGT18cD9dMSYuVvyXXgr73Z9iWYnBbk9jO7tgK15vGu4mWXPhMAoothq6efhZnm2tewK2likoEyYjxlNkwsP+5HscpEr9DVaOeXMO16H5THz1R7nBfznjivN0g5TTW4cMw2EJcq94XfqsiyfqABOmJcJVgMPEuvtDjgpvvBEzc09DNPnoNIquqv6bv0GBgToQ8T6orIyrq5vm+IzZwwOHHUf7iak2bNSraYPm9sXhgULXc3EhMvz+qeT6Mw+sGtxFb43imRSu9uRoH2n9jX8Cqm9xrFisLbeDJ+jTLuRUYUXSaQBPbnryUvNkpW8auWau1w7oxxkSt8iGkJ5HzGGKCRWfrmbHTTTq20etCDvgRBodGjMQZoNVKjAATrtJCs/fNJ0bjT1KNfD5C8ZyLnV/UDeaWw1rTmOIz6tzovo7qzm4J+2Gg+0ZFCCtbD18J+NW9X0fUzYKFsX4Veq0AVQCLIlTHPgtFX1EzLHconIacRj307Vc9t1Ru/bvShZY 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:(13230040)(1800799024)(36860700013)(376014)(82310400026)(7416014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Dec 2024 06:37:39.6671 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 565f4e3d-34e6-4fa7-7255-08dd1a777972 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: CH2PEPF000000A0.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB8822 X-Stat-Signature: 45d47u1q9f6f1kfiwiogtt8sc4pfbzy8 X-Rspam-User: X-Rspamd-Queue-Id: 99A36160002 X-Rspamd-Server: rspam08 X-HE-Tag: 1733985449-63503 X-HE-Meta: U2FsdGVkX19HQpxOJkv/s9K8ydA3nwn+4ylCJzacCvh2qH4hZQsPAtx00/oSnbqnwvH0fH6cbfOw794yU0LHwaN44GNa9XRSCCNV02v8GCqMDqdSxOocrGjRvaXQD0VAeA+j+rMQdJOWbHO575bfXSh+1HJLYTslhzTG1dB0qBH4wD7a5RB+vOD8CCsGE+AN62RZeVlMD8tGX32vQyp2QwOWtNxVRFDxGND7PcdBOK4VI4uHJtXCgeybkjx9qjItoQpMHpzVPCRVqc5NAhpfgDdAZV27vhg1oeNkwM1g7FtwYOh6QzE7eBGhBd69/NN5a3Cbmny0L3z2ebwrOHhI+d50CHGYQAH0MHoBDIAukc2K2mrIdgSrZV8bR2mK9LOK64xdsSTVjGPd5unLNA7Q5xEvd3h+SCwqrDgf0kNjKhizs+6vCojHfhRRf1jGQ2/aPB5HInWkUnJv+m7TEtTuPO1L5FMUOCK4EtGkHN3KYbxWG5Op3PM28y3c5B78Maa4EWL5SZUp/kDHPojq3XndHXJs4bqZXg3D6BmNlB3Dy8OrmPV6c8bMfXWwXs9GCOQO351q90kIirHn1V+fqpv8A/sojn0shXD7N6ISNhk2b9dSPmSrQ8gRUiNsmnMFWweVUGHKUh5ttWvGYLGduPahcKBbtMPMB6MsTOKfzJCjc3hyL8+VKnzJH4QLSn+Fd4YnVsqqoit0KmrBobIxb5W/3JymSlwb0P/7qPua39n1PEG4RLXAyVRFlVuEzKyd2gfUZIFpBeu5172Nrhqdi6rI/ofIh+nurTTu3yvssERb91k+dgiqYZUaWemxaU0puJYiS0DNWUvMAkk19kfLMjYX6CXvvoHy3+YnZpbs6x/m087OSshWNXVo0qwbFU39W/aIJZ8fcXc5oQ3kiWYaN9u9jib+38RCh31P3TG/Ss+Wn2KU3veydEbdiiPCmi9J0eUjEYyCLL5xNpah6kL9crb ZJF86QvZ A69hQAO0unBNf26rgIa+zD3AED6fWeCA6nL5JGeLbZTZczYmnxA/JuoesVza0HC3t0eoj/c0l3uFtChL2c7N3ZEf66XV7Isg4MTGBQ0fZIhFOmk0lROcAioDwzRCYVLgJzvGsw0Jy1PgGq9EV4RYu3w77E6FZC8AO/9WcBwrYPSHfnGp1jK3ZQzktyZuoPalruRbPmclh0t/c6adkGyW4PLCbMM53f34R7GMIw+dCiAKPJwL7/31bQ+ajiyDt5LPYOOlOPu2kobVIyH5vaoprxSoY+3DAuE7DtZw4sXXY8Yr3L4gAbo6or9ntzGIXzfMKiJ90Mays5rEo31OzAEFyW1/spgj4vasOVYduKX/eR14dGGDcbllSvD6TBDjOZ4i3VSn/TjPcDw/82L00DBwGcZ5UhjH9IyvSi4/G3EauW14HV1Q5kodmGEkHuibd1/RU6INdiui+wG4c+ilruUPLN+UcExMFug9AYfnUFIc8MfUgrAHegRaJmaI7nv4GKbIgCzTpUPt49N63gI3HNvBxdF6S70KGumeZb+ed+4jxeV14S48= 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: List-Subscribe: List-Unsubscribe: Currently __kvm_gmem_get_pfn() sets 'is_prepared' so callers can skip calling kvm_gmem_prepare_folio(). However, subsequent patches will introduce some locking constraints around setting/checking preparedness that will require filemap_invalidate_lock*() to be held while checking for preparedness. This locking could theoretically be done inside __kvm_gmem_get_pfn(), or by requiring that filemap_invalidate_lock*() is held while calling __kvm_gmem_get_pfn(), but that places unnecessary constraints around when __kvm_gmem_get_pfn() can be called, whereas callers could just as easily call kvm_gmem_is_prepared() directly. So, in preparation for these locking changes, drop the 'is_prepared' argument, and leave it up to callers to handle checking preparedness where needed and with the proper locking constraints. Signed-off-by: Michael Roth --- virt/kvm/guest_memfd.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c index b69af3580bef..aa0038ddf4a4 100644 --- a/virt/kvm/guest_memfd.c +++ b/virt/kvm/guest_memfd.c @@ -773,7 +773,7 @@ void kvm_gmem_unbind(struct kvm_memory_slot *slot) static struct folio *__kvm_gmem_get_pfn(struct file *file, struct kvm_memory_slot *slot, pgoff_t index, kvm_pfn_t *pfn, - bool *is_prepared, int *max_order) + int *max_order) { struct kvm_gmem *gmem = file->private_data; struct folio *folio; @@ -803,7 +803,6 @@ static struct folio *__kvm_gmem_get_pfn(struct file *file, if (max_order) *max_order = 0; - *is_prepared = kvm_gmem_is_prepared(file, index, folio); return folio; } @@ -814,19 +813,18 @@ int kvm_gmem_get_pfn(struct kvm *kvm, struct kvm_memory_slot *slot, pgoff_t index = kvm_gmem_get_index(slot, gfn); struct file *file = kvm_gmem_get_file(slot); struct folio *folio; - bool is_prepared = false; int r = 0; if (!file) return -EFAULT; - folio = __kvm_gmem_get_pfn(file, slot, index, pfn, &is_prepared, max_order); + folio = __kvm_gmem_get_pfn(file, slot, index, pfn, max_order); if (IS_ERR(folio)) { r = PTR_ERR(folio); goto out; } - if (!is_prepared) + if (kvm_gmem_is_prepared(file, index, folio)) r = kvm_gmem_prepare_folio(kvm, file, slot, gfn, folio); folio_unlock(folio); @@ -872,7 +870,6 @@ long kvm_gmem_populate(struct kvm *kvm, gfn_t start_gfn, void __user *src, long struct folio *folio; gfn_t gfn = start_gfn + i; pgoff_t index = kvm_gmem_get_index(slot, gfn); - bool is_prepared = false; kvm_pfn_t pfn; if (signal_pending(current)) { @@ -880,13 +877,13 @@ long kvm_gmem_populate(struct kvm *kvm, gfn_t start_gfn, void __user *src, long break; } - folio = __kvm_gmem_get_pfn(file, slot, index, &pfn, &is_prepared, &max_order); + folio = __kvm_gmem_get_pfn(file, slot, index, &pfn, &max_order); if (IS_ERR(folio)) { ret = PTR_ERR(folio); break; } - if (is_prepared) { + if (kvm_gmem_is_prepared(file, index, folio)) { folio_unlock(folio); folio_put(folio); ret = -EEXIST;