From mboxrd@z Thu Jan 1 00:00:00 1970 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 E95C4C36018 for ; Wed, 2 Apr 2025 22:18:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6ECB0280003; Wed, 2 Apr 2025 18:18:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 69AB7280001; Wed, 2 Apr 2025 18:18:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 511AA280003; Wed, 2 Apr 2025 18:18:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 36185280001 for ; Wed, 2 Apr 2025 18:18:00 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 6B4B7C08BB for ; Wed, 2 Apr 2025 22:18:01 +0000 (UTC) X-FDA: 83290517562.21.6A60268 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2056.outbound.protection.outlook.com [40.107.94.56]) by imf12.hostedemail.com (Postfix) with ESMTP id 5FDBA40011 for ; Wed, 2 Apr 2025 22:17:58 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=PeWXXXEJ; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf12.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.94.56 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1743632278; a=rsa-sha256; cv=pass; b=M6raujv+uN8UGrBWvc1oLywcKq9cM9/vgEoJwEC12hs8Q2jhvXTtS37hs7fB0f9WCgLyO1 hScmwvCluZOWjAES2hFs3CA80npkLB4QzjrfKx1Ijm4PpzUI4EkvDuGAnGtWr9kEtPGTcX TASdDVoHYReY806v1IX/mAd6xXxmvTY= ARC-Authentication-Results: i=2; imf12.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=PeWXXXEJ; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf12.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.94.56 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=1743632278; 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=hBN1GNCKPC8jWPPRSxQeM7OeaQvUytNA+k2sj4hhY6g=; b=OxRt6eFWhMZR4SfV1P10s61Oxvs4wJ93HARCpbIX3AdtI5ldSh48QRht4M39hPR071ekT8 NJ26fabb/7OCl5ngM3u4VpTOU3bvAXJsOoU6ZunFgN1/ZzqjLH6uN0tTkXJFSFDcAXLney yN4BbpR5ppzvVA/tFo9IBuKDWuIAHus= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=u1kvf/jHFRZzcgQuS6RiqCb2xCEHXlqYIGBU5zG42P3vkPGGAbebxuOOYmg4iN609AnAdFsh0r/amBf+grsR7TZ14H07fgpzHQNAEn1h+/SygDuFJsxVi1uChP4/9QjoBgUa313IX/uDKyAlv7+LXVCB8P3MB6A/1UB9G1jmP8DesDaHyjsZijz8DEh+XQU3iaoEbfT4e3b6PrIJJbp2rUX9UdzMoB4PzsztxB0Xm36fquBKRR0o0fBliXFgWgTYNCRjKqM6B1Wq+bk7qXZp3MAtpiPNTKzs0HKH63SOfoYRq+iUY9n02Ypp3TDwX4+HUgpq/EfmOHriAiPY86dHbQ== 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=hBN1GNCKPC8jWPPRSxQeM7OeaQvUytNA+k2sj4hhY6g=; b=FsJUyspO15tU+dZFq2i6oTgn1MM9A7IgSMv8Ouqq54K0JSySaYtuU275+fAslTauWTrcPQe4nQt++BllwV+KvqBY0It4RW+KQuqnlocEmhe45uvgDmuYdT9Ae/ViHSV1AxjpDL7AIAR6Eq4UxP5QE41C0RPKCTbVUxR6nPGOxcOC9tJk/+TamylCvXcKg7aq4Y5r7fQyR7jfOkkmlTTp15zIjxkwWvU9FQNS3DQ2Yb/E3E8bNWOTOQztkFBKABfpmGvBXGdcaiAqWZ5mwBMwvE3aTg1AmrG/VZx09EfZ82NhYnPSzNJsNLpBjXlkBimJF7dgJsD8AaeffVFnPrXLrA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=google.com 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=hBN1GNCKPC8jWPPRSxQeM7OeaQvUytNA+k2sj4hhY6g=; b=PeWXXXEJLoQfYHv5m+kOfmdrfSVB1s1j/wikbvmPLfj7eId9Sgv3UTIpmAnqfEM+dUF+shw3AKfUwdZTnE36P0J29tde1GFGQwnu1CFKdGQ/Fgdqi0OOpQ9FCmLGFu2x/vfNGokDjI8SzFXg9ZIqVBSIl9nxCLNDToDZWrukeRI= Received: from BL1PR13CA0377.namprd13.prod.outlook.com (2603:10b6:208:2c0::22) by PH8PR12MB6867.namprd12.prod.outlook.com (2603:10b6:510:1ca::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8534.50; Wed, 2 Apr 2025 22:17:54 +0000 Received: from MN1PEPF0000F0E2.namprd04.prod.outlook.com (2603:10b6:208:2c0:cafe::b1) by BL1PR13CA0377.outlook.office365.com (2603:10b6:208:2c0::22) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8632.9 via Frontend Transport; Wed, 2 Apr 2025 22:17:53 +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 MN1PEPF0000F0E2.mail.protection.outlook.com (10.167.242.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8606.22 via Frontend Transport; Wed, 2 Apr 2025 22:17:53 +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; Wed, 2 Apr 2025 17:17:53 -0500 Date: Wed, 2 Apr 2025 17:17:39 -0500 From: Michael Roth To: Fuad Tabba CC: Vishal Annapurve , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: Re: [PATCH v6 5/7] KVM: guest_memfd: Restore folio state after final folio_put() Message-ID: <20250402221739.yqvuuiuxvvphgijd@amd.com> References: <20250318162046.4016367-1-tabba@google.com> <20250318162046.4016367-6-tabba@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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: MN1PEPF0000F0E2:EE_|PH8PR12MB6867:EE_ X-MS-Office365-Filtering-Correlation-Id: 89233117-8d5f-4792-be8b-08dd723436c9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|82310400026|36860700013|1800799024|13003099007|7053199007; X-Microsoft-Antispam-Message-Info: =?utf-8?B?aWkvekQxcDk0NXA5akx4NEhZY1dIN0NjQytFUUtLUlFqL3NCdXlnMit6bHJJ?= =?utf-8?B?MWs0Tytwd3NVanJDSUtneWsrZTg3OC91UHJJSFJndVhVQmxveFRPaUNDY1U2?= =?utf-8?B?YjZ4Y3ZCVlIxTmFFdHJVNnN5Q3QzdkROV3pyR3ZYbS9aV0ZWTnNhNDBlZU85?= =?utf-8?B?UXFOUFZmNWpqUWUwN2E3dlVkRmUrdjRXR3JROWNkeDF1Z0tzRUtGZXh2VEJi?= =?utf-8?B?TW1qbEZFVXVCeTI0R3NSVzhGTGtxVlFTR0w0VkVDVTg1N2JzMDJVOVY2eUZX?= =?utf-8?B?Y3YxSTZLdzVOUEloS3NsK0NhSkhDOGFTdmVoRlpUa0NRZHplNXN6VlQ3cFJI?= =?utf-8?B?M1VCK2t0VWQ3Z1JnNHdKYWwxeDFvc3p5d3JOdWo1VTQrVXNRTjArVWhta1Er?= =?utf-8?B?VWZEeHVxemhjTmsxaTBYNDJUQ2RFSUdkN20vK3pvTG5QNmsxRS8zZ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dHBnL3BFSmRWcjFGMFly?= =?utf-8?B?U1NaM0owaHBZNm5mZzhPNzN2Z3E2ZVB2SWpnWGVsQkJEejRMeUtGWXFiRkRu?= =?utf-8?B?VER0SU00Z2MxSjVZTXZwZUJsV2U4aHhIM3pZQVgzUlkxbW1FcHRJY01wK2h4?= =?utf-8?B?UnZQeG5RU2x2YVRITmpBNU9xSUk2TkkrTjlnZ0pZVVdCY2tPZ2NSYU1UR1lS?= =?utf-8?B?dVlkZFE2NkhCVk9nQ1BtZWJNN3hCVFJaU2swNiszUFhQT1d4bTgvYWluRlNX?= =?utf-8?B?T1ZXNHIwU0NuNXNLOUpRbm5MeENneHJHWUxJeDN5bmxJa2REK3VaSVJuVU0r?= =?utf-8?B?QUJWbFEwbG1Xek15YXJBTzRRc2dtUUJIV2lBZzNSYzRabWFiQVNRcENmK05E?= =?utf-8?B?SEw3L3I3Y000NkljbC8vR3pGZGN3TW4zSDVncXRtTTErMUVJc2paMW1xTUVE?= =?utf-8?B?cnVFUHFPR1lLVnZSdHNGUlNBNm00a3pueXRDaTlXaFZTekQwWVVXcFBkT0lj?= =?utf-8?B?T1JCTkVhaC9Bb3RCWmJwWTNGemVRWHBYVFJ3c0xvVXJDbHkzZ3drNjFwWUM3?= =?utf-8?Q?27ZrAHCrYo0=3D?= 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)(376014)(7416014)(82310400026)(36860700013)(1800799024)(13003099007)(7053199007);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Apr 2025 22:17:53.8910 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 89233117-8d5f-4792-be8b-08dd723436c9 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: MN1PEPF0000F0E2.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB6867 X-Rspamd-Queue-Id: 5FDBA40011 X-Stat-Signature: ozkczi98iocbgoqzscrpd8p5s76uooma X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1743632278-491997 X-HE-Meta: U2FsdGVkX18F95hdsvFIOlHrT/x2PmO88BEOfXHhc+b8Hd9PtFSA2wUHCL7Lk1El8eBldIAThlvwTna8uqCWAnlOWWPo+fOvm3mdeJXvOBUElCPGB0jS/IEr/4dStqi2cCGhEsSKA3F9/HNq/NgSHii4swEGbtT2Y1QA/kXIQ7UYAJJRsD9LPzYrONT6r85XxYCI6ZLhjXKpEpT70oXfxuc2h1KPe8J9BQTt+dNiFNGn1LtOZPdPLXSW1WlDA2lhAeHIIBVIKhPcQ+Xwn0OWejsa0HaFUXWD43Nwa9gO5rHaGBo7dB0zZIVdwvRdyJ42LHoF5whzRHf9GgDcK+MpDbKA6Z+lThgDs6zXFoegejfictpuiUNOdYknO7OIs453i+j2N6AWeVQA7DLw0bPLiqxEm4MJtQVlOtArwwyrZ7oMpGz6JujzerX6MamazeblFur9C5VDiKl4VZrbDtP6BZ5NBsv96LLmZjfyDqCilGlngw5D8pk52rLzVT8eGt/sr79pSc7JsuC8mSJLS2Lm82sdoCNWvWooLUOPlBxlV+J41JD/R0twcxUGPUZiPJSIJhBI1mq+TcXDxp4BMNZaqkbEWoMQzk7ZmzAYVwlh7LhGAVnCPZsMNfz5eE4GnmKkHTenW15jcla34mYdBoID+A04qd5tk3RW0S3zw7lyYl7Aa3V/y/5Kf4ZZ+D6QVwRBHnijsnhnnD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YPxiaRhukw8k= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000598, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Tue, Mar 25, 2025 at 03:57:00PM +0000, Fuad Tabba wrote: > Hi Vishal, > > > On Fri, 21 Mar 2025 at 20:09, Vishal Annapurve wrote: > > > > On Tue, Mar 18, 2025 at 9:20 AM Fuad Tabba wrote: > > > ... > > > +/* > > > + * Callback function for __folio_put(), i.e., called once all references by the > > > + * host to the folio have been dropped. This allows gmem to transition the state > > > + * of the folio to shared with the guest, and allows the hypervisor to continue > > > + * transitioning its state to private, since the host cannot attempt to access > > > + * it anymore. > > > + */ > > > void kvm_gmem_handle_folio_put(struct folio *folio) > > > { > > > - WARN_ONCE(1, "A placeholder that shouldn't trigger. Work in progress."); > > > + struct address_space *mapping; > > > + struct xarray *shared_offsets; > > > + struct inode *inode; > > > + pgoff_t index; > > > + void *xval; > > > + > > > + mapping = folio->mapping; > > > + if (WARN_ON_ONCE(!mapping)) > > > + return; > > > + > > > + inode = mapping->host; > > > + index = folio->index; > > > + shared_offsets = &kvm_gmem_private(inode)->shared_offsets; > > > + xval = xa_mk_value(KVM_GMEM_GUEST_SHARED); > > > + > > > + filemap_invalidate_lock(inode->i_mapping); > > > > As discussed in the guest_memfd upstream, folio_put can happen from > > atomic context [1], so we need a way to either defer the work outside > > kvm_gmem_handle_folio_put() (which is very likely needed to handle > > hugepages and merge operation) or ensure to execute the logic using > > synchronization primitives that will not sleep. > > Thanks for pointing this out. For now, rather than deferring (which > we'll come to when hugepages come into play), I think this would be FWIW, with SNP, it's only possible to unsplit an RMP entry if the guest cooperates with re-validating/re-accepting the memory at a higher order. Currently, this guest support is not implemented in linux. So, if we were to opportunistically unsplit hugepages, we'd zap the mappings in KVM, let it fault in at a higher order so we could reduce TLB misses, and then KVM would (via kvm_x86_call(private_max_mapping_level)(kvm, pfn) find that the RMP entry is still split to 4K, and remap everything right back to the 4K granularity it was already at to begin with. TDX seems to have a bit more flexibility in being able to 'unsplit'/promote private ranges back up to higher orders, so it could potentially benefit from doing things opportunistically... However, ideally...the guest would just avoid unecessarily carving up ranges to begin with and pack all it's shared mappings into smaller GPA ranges. Then, all this unsplitting of huge pages could be completely avoided until cleanup/truncate time. So maybe even for hugepages we should just plan to do things this way, at least as a start? > possible to resolve by ensuring we have exclusive access* to the folio > instead, and using that to ensure that we can access the > shared_offsets maps. > > * By exclusive access I mean either holding the folio lock, or knowing > that no one else has references to the folio (which is the case when > kvm_gmem_handle_folio_put() is called). > > I'll try to respin something in time for folks to look at it before > the next sync. Thanks for posting. I was looking at how to get rid of filemap_invalidate_lock() from conversion path, and having that separate rwlock seems to resolve a lot of the potential races I was looking at. I'm working on rebasing SNP 2MB support on top of your v7 series now. -Mike > > Cheers, > /fuad > > > [1] https://elixir.bootlin.com/linux/v6.14-rc6/source/include/linux/mm.h#L1483 > > > > > + folio_lock(folio); > > > + kvm_gmem_restore_pending_folio(folio, inode); > > > + folio_unlock(folio); > > > + WARN_ON_ONCE(xa_err(xa_store(shared_offsets, index, xval, GFP_KERNEL))); > > > + filemap_invalidate_unlock(inode->i_mapping); > > > } > > > EXPORT_SYMBOL_GPL(kvm_gmem_handle_folio_put); > > > > > > -- > > > 2.49.0.rc1.451.g8f38331e32-goog > > > >