From patchwork Fri Nov 22 17:29:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elliot Berman X-Patchwork-Id: 13883454 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 8CF1DE69185 for ; Fri, 22 Nov 2024 17:30:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D00E66B0088; Fri, 22 Nov 2024 12:29:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CB0756B0089; Fri, 22 Nov 2024 12:29:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B29F26B008A; Fri, 22 Nov 2024 12:29:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 9A49D6B0088 for ; Fri, 22 Nov 2024 12:29:59 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 525AD80FAD for ; Fri, 22 Nov 2024 17:29:59 +0000 (UTC) X-FDA: 82814417868.04.AF742BA Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by imf03.hostedemail.com (Postfix) with ESMTP id 554CB20025 for ; Fri, 22 Nov 2024 17:29:32 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b="J6u/19z1"; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf03.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732296529; a=rsa-sha256; cv=none; b=lp27YeoMArq5YJQmKXuA7BiQyQioZJifu6NdlbKIvFZap1lyUc/1qLgz7wz2hdZOeofwJU ZOFe4Ka4mqeFq7JQr/QE/KJrkyYL4PpX8oypfgWXdAZ9L8VN8mnGN8D23rCxmV3LVsiAv2 J81XeHHAGxcSGKRyyCr37w+dcmXCMTM= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b="J6u/19z1"; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf03.hostedemail.com: domain of quic_eberman@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_eberman@quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732296529; 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: references:dkim-signature; bh=XQD1PU6ptvKeI0fuFGCRRHzhvac3i1byGnmnm5ZKMNQ=; b=xT7MPPy7SaEH9VF50OP46c6cBFJzDwzYU5r/JIBlYa0Os6J/klhZ6r3n9wgYwITgymsn11 WLwAKyYRHd+s/W30Kh1EL5Cke1YT18B/kanu7IW7QaQPvxBzSSaPSMVfVvq3jxp5b3CszW HA+lxmpD/5AkQjMZs0EWUE4tZNBVlMc= Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4AMAMOeZ020697; Fri, 22 Nov 2024 17:29:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to; s=qcppdkim1; bh=XQD1PU6ptvKeI0fuFGCRRH zhvac3i1byGnmnm5ZKMNQ=; b=J6u/19z19r8pbkyVFouVXseewIRW9lf/XXr5OY xMtAMdYaR3wbGrkPjNxVCsc/cdxs5Esu1wm8TydJwBef+M0BvxaSF9jfDpYnYmlX +NYxvkagKjvymiPGHp3V36XefLFtIiHUGHY/Ys1DKRbfZxyNxOWRWrkkGjOmYut3 5juU7WFtSNtEhTnw2VmGVr6wOmeH4/e9RpCHAfnaZm6yKReEWAjAZdBKokIgW70C g0OKLCxgXEDYM5RhHvopGMf1BeBSEU3vCTaL6UwIS4NzDhtoXiTichlvFIgPmhfo vzmP+fYvX1Dvf3M28vvcC3EXX+mxASbVbFC4QPokrTRSClSw== Received: from nasanppmta04.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 431sv2nwj4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 22 Nov 2024 17:29:43 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA04.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4AMHTgut021006 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 22 Nov 2024 17:29:42 GMT Received: from hu-eberman-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Fri, 22 Nov 2024 09:29:41 -0800 From: Elliot Berman Subject: [PATCH v5 0/2] mm: Refactor KVM guest_memfd to introduce guestmem library Date: Fri, 22 Nov 2024 09:29:37 -0800 Message-ID: <20241122-guestmem-library-v5-0-450e92951a15@quicinc.com> MIME-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAIG/QGcC/23NTQ6CMBCG4auQrq3pD7TUlfcwLqAMMImAttBIC He3kJhodPl+yTyzEA8OwZNTshAHAT0OfYzskBDbFn0DFKvYRDCRcs4FbSbwYwcdvWHpCjdTlUs lbSkMzxWJZ3cHNT538nKN3aIfBzfvH4Lc1jcmf7EgKaOa1xVAnimtyvNjQou9PdqhIxsX0g9Cs D9EGglmM6NrLaVh5ptY1/UFy5Xc0vUAAAA= X-Change-ID: 20241112-guestmem-library-68363cb29186 To: Paolo Bonzini , Andrew Morton , Sean Christopherson , "Fuad Tabba" , Ackerley Tng , "Mike Rapoport" , David Hildenbrand , "H. Peter Anvin" , "Matthew Wilcox (Oracle)" , Jonathan Corbet , Trond Myklebust , "Anna Schumaker" , Mike Marshall , "Martin Brandenburg" , Alexander Viro , Christian Brauner , Jan Kara CC: James Gowans , Mike Day , , , , , , , , , , , "Elliot Berman" X-Mailer: b4 0.14.2 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: F6Lm3BVFcc9UAbluTuBt_BvMDPNh2TaM X-Proofpoint-ORIG-GUID: F6Lm3BVFcc9UAbluTuBt_BvMDPNh2TaM X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 lowpriorityscore=0 clxscore=1015 bulkscore=0 adultscore=0 suspectscore=0 spamscore=0 malwarescore=0 mlxscore=0 mlxlogscore=984 phishscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411220147 X-Rspam-User: X-Rspamd-Queue-Id: 554CB20025 X-Rspamd-Server: rspam01 X-Stat-Signature: 798kccxpduqdxo9physxbsbgws5auy17 X-HE-Tag: 1732296572-520488 X-HE-Meta: U2FsdGVkX1/lNnrpGdp/1zqLmYqMG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IKgEKJJge2S5Ukpdr0Sa82H8k09u5FpWxGljafNlF5afwgzoZi8HFvCUsduV9ERJFQApaIXrO1+xJkCmlNEBHcT+hlfNf9Uy2MVnVc+Hl+JBA2BfBzPXz+1EOO6eGjEmOeRB6kQWHmd7p7DfVM5QLAgbjy0LyxLpyX/dL/8K4/LJ7WnCcy0g0aESGT/3XaLHB207kNVSMNq2WgRUMH/9Xk+okVy9EtA7BgaPLxoqZP+4/VH1Eedv/ehm1xCJLzOklSsZ/+4ATOCV00xJ8Qiek4qrpWtX7wORQrT97Trur2N8Os8R9EQ/MoAdH36xHKrOBoLHdXnJfGFUd 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: In preparation for adding more features to KVM's guest_memfd, refactor and introduce a library which abtracts some of the core-mm decisions about managing folios associated with guest memory. The goal of the refactor serves two purposes: 1. Provide an easier way to reason about memory in guest_memfd. KVM needs to support multiple confidentiality models (TDX, SEV, pKVM, Arm CCA). These models support different semantics for when the host can(not) access guest memory. An abstraction for the allocator and managing the state of pages will make it eaiser to reason about the state of folios within the guest_memfd. 2. Provide a common implementation for other users such as Gunyah [1] and guestmemfs [2]. In this initial series, I'm seeking comments for the line I'm drawing between library and user (KVM). I've not introduced new functionality in this series; the first new feature will probably be Fuad's mappability patches [3]. I've decided to only bring out the address_space from guest_memfd as it seemed the simplest approach. In the current iteration, KVM "attaches" the guestmem to the inode. I expect we'll want to provide some helpers for inode, file, and vm operations when it's relevant to mappability/accessiblity/faultability. I'd appreciate any feedback, especially on how much we should pull into the guestmem library. [1]: https://lore.kernel.org/lkml/20240222-gunyah-v17-0-1e9da6763d38@quicinc.com/ [2]: https://lore.kernel.org/all/20240805093245.889357-1-jgowans@amazon.com/ [3]: https://lore.kernel.org/all/20241010085930.1546800-3-tabba@google.com/ Changes in v5: - Free all folios when the owner removes detaches the guestmem - Link to v4: https://lore.kernel.org/r/20241120-guestmem-library-v4-0-0c597f733909@quicinc.com Changes in v4: - Update folio_free() to add address_space mapping instead of invalidate_folio/free_folio path. - Link to v3: https://lore.kernel.org/r/20241113-guestmem-library-v3-0-71fdee85676b@quicinc.com Changes in v3: - Refactor/extract only the address_space - Link to v2: https://lore.kernel.org/all/20240829-guest-memfd-lib-v2-0-b9afc1ff3656@quicinc.com/ Changes in v2: - Significantly reworked to introduce "accessible" and "safe" reference counters - Link to v1: https://lore.kernel.org/r/20240805-guest-memfd-lib-v1-0-e5a29a4ff5d7@quicinc.com Signed-off-by: Elliot Berman Tested-by: Mike Day --- Elliot Berman (2): filemap: Pass address_space mapping to ->free_folio() mm: guestmem: Convert address_space operations to guestmem library Documentation/filesystems/locking.rst | 2 +- MAINTAINERS | 2 + fs/nfs/dir.c | 11 +- fs/orangefs/inode.c | 3 +- include/linux/fs.h | 2 +- include/linux/guestmem.h | 34 ++++++ mm/Kconfig | 3 + mm/Makefile | 1 + mm/filemap.c | 9 +- mm/guestmem.c | 201 ++++++++++++++++++++++++++++++++++ mm/secretmem.c | 3 +- mm/vmscan.c | 4 +- virt/kvm/Kconfig | 1 + virt/kvm/guest_memfd.c | 98 +++++------------ 14 files changed, 290 insertions(+), 84 deletions(-) --- base-commit: 5cb1659f412041e4780f2e8ee49b2e03728a2ba6 change-id: 20241112-guestmem-library-68363cb29186 Best regards,