From patchwork Thu Aug 1 09:01:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13749992 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 92C85C3DA64 for ; Thu, 1 Aug 2024 09:01:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0E65F6B008A; Thu, 1 Aug 2024 05:01:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0BDAF6B0092; Thu, 1 Aug 2024 05:01:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EC7A46B0093; Thu, 1 Aug 2024 05:01:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id C82466B008A for ; Thu, 1 Aug 2024 05:01:25 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 847F0A697A for ; Thu, 1 Aug 2024 09:01:25 +0000 (UTC) X-FDA: 82403082930.15.1C4AE7F Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf28.hostedemail.com (Postfix) with ESMTP id B1927C002A for ; Thu, 1 Aug 2024 09:01:23 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=KZtL2XlU; spf=pass (imf28.hostedemail.com: domain of 34k6rZgUKCGkaHIIHNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--tabba.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=34k6rZgUKCGkaHIIHNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--tabba.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722502878; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=55lqFFECQwDLNrYt4aytrJso1NybdDvPLt3jS/2DBHA=; b=fk34soNMVc06wcqMlprFiXWK6kdGFLOEBvYdowU9cA+FfeYmPKpDQNYIqP6ac0ERPgmy06 4xc7g/LDsUMHKcG1veilsj1l4k7jxSYcqrlgNGU4dAqYLRpmC1KMxct2ax8Eyl5AF2u/Jv ZYgdGnqqdXeuTdfGNqQOBV3hhHXAy5E= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=KZtL2XlU; spf=pass (imf28.hostedemail.com: domain of 34k6rZgUKCGkaHIIHNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--tabba.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=34k6rZgUKCGkaHIIHNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--tabba.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722502878; a=rsa-sha256; cv=none; b=YIn/pMdFs4z6kxHHHCc776KHjmWdw2wU0otNk8oU5OGmHFOAWrvjk5K2yXX2K5qK65MgVY CezdWwu2vm0CV+Xt2V9sogAjG4PuI1cg+Xak4dsWoczieJyDu6UvLEvegZoiTnCRz4VxnD RHPSwX3OntvMbIGiGbx+gk9uMyltW3Q= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-650b621f4cdso124035567b3.1 for ; Thu, 01 Aug 2024 02:01:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722502883; x=1723107683; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=55lqFFECQwDLNrYt4aytrJso1NybdDvPLt3jS/2DBHA=; b=KZtL2XlUCT+512u4tHl239eruPbd1Q9YdclR3KDnH9+KDeHxUFaW4zkU8tHcf/jVFl nXMHr6027iElzIhqqQMzJFSfInaQlVRIIAcQ9371U33GzRLoYPQ/hBozO1Yl1kQmcCJh IAs0g5PzWne/tCERsjiNW599nTAr5yFC4gsYOF9xzjKQqI+bndx9GYVYcdrDvBWCh0ek rtWWp9wFtklvi5S/keQmeAEhdf2gBV+d3p/2x1mmp12/NTMVnE2RYbKUAIsMnaFCTSRv 5zNHlU1y5lfzWOfaLkq6ymWobslukckcb0XmeobZvVbBCvbmXiCfFTFv0zcozx7ZaEYm fQCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722502883; x=1723107683; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=55lqFFECQwDLNrYt4aytrJso1NybdDvPLt3jS/2DBHA=; b=vBA1toRMyL8yYwAGZV2OZOqjZWjt19L+iCgVs9ttIMyfWLHKwfwxkv0PVqlycG+wSx O8eflHVMO+NyHC1dIUHJ0NfLZIhE58Z0bccmgP7Vdu/ik4zO9e/eqUHme9rAYY4gRIhy mlOn38Bnq3Hz7IXfI7hFwbrU6oE01MqlWECIVr/0niAkwrd/ErjjNAA6AMB4XGzrTNM6 cHty6Hfz+JWpSXY9rMjCZao39W0a/dvx35mU3OUSJSoChNwhFOjRX4nK0YdGBtHrKxtk UQipdORXsWbrD7mq6KpKvRFI6wrX8BEmIyQqpyqAUIzDM1NrHT4bBOsmeLEUkAq5u6sf 2a+A== X-Forwarded-Encrypted: i=1; AJvYcCUqNfujtphgPiWG/uR2/cG3g/pT4IIgEiERvn8zXrWSVHuaj640USNNkdaRwWwEVO6GAancCPW+pqpiVA3XAZU+fC4= X-Gm-Message-State: AOJu0YxqIZrDL4r6Ihj8DbbTdGMY5TkIgsup1r9xcAfoEhG2tc0/5qWw +C7TuZaqxLuVeVdpi7VBDoi8fY88dghV96wxXvXXnSR6BsxNAuWvPbSFkmk0sjDqI3DEA8/l3w= = X-Google-Smtp-Source: AGHT+IFXjhPCx5Vb6+Hy1aNGDM/3GXCZNNlq0AHfSY4+hcUlvoRXu5eLes4iJzd35wbNh934dQJX6BHp3A== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:a05:690c:f05:b0:648:3f93:68e0 with SMTP id 00721157ae682-6875028afcamr1291237b3.6.1722502882722; Thu, 01 Aug 2024 02:01:22 -0700 (PDT) Date: Thu, 1 Aug 2024 10:01:08 +0100 In-Reply-To: <20240801090117.3841080-1-tabba@google.com> Mime-Version: 1.0 References: <20240801090117.3841080-1-tabba@google.com> X-Mailer: git-send-email 2.46.0.rc1.232.g9752f9e123-goog Message-ID: <20240801090117.3841080-2-tabba@google.com> Subject: [RFC PATCH v2 01/10] KVM: Introduce kvm_gmem_get_pfn_locked(), which retains the folio lock From: Fuad Tabba To: kvm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-mm@kvack.org Cc: pbonzini@redhat.com, chenhuacai@kernel.org, mpe@ellerman.id.au, anup@brainfault.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, viro@zeniv.linux.org.uk, brauner@kernel.org, willy@infradead.org, akpm@linux-foundation.org, xiaoyao.li@intel.com, yilun.xu@intel.com, chao.p.peng@linux.intel.com, jarkko@kernel.org, amoorthy@google.com, dmatlack@google.com, yu.c.zhang@linux.intel.com, isaku.yamahata@intel.com, mic@digikod.net, vbabka@suse.cz, vannapurve@google.com, ackerleytng@google.com, mail@maciej.szmigiero.name, david@redhat.com, michael.roth@amd.com, wei.w.wang@intel.com, liam.merwick@oracle.com, isaku.yamahata@gmail.com, kirill.shutemov@linux.intel.com, suzuki.poulose@arm.com, steven.price@arm.com, quic_eberman@quicinc.com, quic_mnalajal@quicinc.com, quic_tsoni@quicinc.com, quic_svaddagi@quicinc.com, quic_cvanscha@quicinc.com, quic_pderrin@quicinc.com, quic_pheragu@quicinc.com, catalin.marinas@arm.com, james.morse@arm.com, yuzenghui@huawei.com, oliver.upton@linux.dev, maz@kernel.org, will@kernel.org, qperret@google.com, keirf@google.com, roypat@amazon.co.uk, shuah@kernel.org, hch@infradead.org, jgg@nvidia.com, rientjes@google.com, jhubbard@nvidia.com, fvdl@google.com, hughd@google.com, tabba@google.com X-Rspam-User: X-Stat-Signature: s3m4c79ydek8szsgmaiqsyo3f1efdmix X-Rspamd-Queue-Id: B1927C002A X-Rspamd-Server: rspam11 X-HE-Tag: 1722502883-321158 X-HE-Meta: U2FsdGVkX1+feeKhJPc3KJ1vsQ7xnkzx0GcGZG1o7NNpQtbxe3tWMoyvxxKgc+yTTXQwvZnBC3rYlGwvh90CyV0g/jKQqrxF7R4UjZf2WQpOjgu+EoFftrEnRCpayvxxtKFLIShPV0Y9hukYsvH1ZX8M8lMjzLkdooy7VAZqSDXyWZ2VgSJCBGlCTJk9OQIfvqOO5D0cD7VSe0zDYI8hsu1htP+62Ivha0yhU4AYOmyYNqg2jiC8fjqeRorB+GJudw44SfVrptzbCbgxmoUxbSp3gWtcFN7pK7K4PYu36TYW9qSwP+a2AWyJVk5O+QY+Bip8W1YKqiwxYrKSlHat9ZqkELDZYgEohAHGOPWt+ZmpJfb0NV1286AnVvE4r9qRK5zSL35WuiD6UE92aWeKrcf2kGNpbBFnwoVHpS6uLzY72upNNvTaiNcVPU+zLXBFwY7CJt1521oQGiJt/WHysuZ44eZwr/+IOJe7ODqmJ6YZeiZZ5WCHd9TQfHB13T5kddfyWLpQPh81da6s/jcPP0Otw23uTDCJc/XDT5sFtH/WbrwKCo3uIwt06Am0fRLCZoWwf4uVuHqiQZQ6lmIGyexgzhRuvZLjDvZ0CKjjS/3Cs+V73KZtSwYYzcVLWw9qVnYZvqyz+U1iqZV3Ch8d0C9Efep2y7qmUWZ0ciQpQ7FyoUTOkKFN+Qz/KQ7yUb6aETLwrqHzzypEDDA2Fy6QpgeNR0HNBG2tm8UEVx1QAoz42hS4ZlhU/TcrNsWFA7+JDsdryqrblDx794Us3kJDlmox1GZwBWfHS4KNguK94UOiT6n2zrTmwspVbrertynumoSxj2rMvmmhEWDDRQ5ns64XYFcJCZC0WLRq6kgwEmEGnDKAPB1GRQ1KclICcqISEy0MVz+gAg18cWwzeL629cpDCOqcEmUfhTEaIC0J7vaW2MdYOkxeDIFZ9vmX5DBMQf3eUuCd3gf81lvmPJn +3QQSZDa lBH0wpRZ3CcZQzzK/Q+KE8nuJQT9MU2RP7cOIl3E3/+JEGljirWZyxFf2H+hp2SL2cYOMcJj+PmvUZtrH2rGTWc7b5wUWLVvDoBXSq1cXB6xm3uCIT+wPX65J/CoVzb0LpVqS4HLqDbBpF7Cmu7Xuji/AEUmZW/gtBMjFHK09OwK/F5CnMb5BHuuDu2wXQGM2/Q5occcjh2nfMrgd6pH71tIbangztiRHIfby9h1kuoWVfGJmDH5iHQ1XzV8jfN3n8aKCtwe38WEuqXr0184bhs6/eBxupxww31IK5sk1XGNdiDyJXx9g1lYJKh5uRlK/G2rdUZ1dGd1PE0V/FjEEULP4MT+43F8/XcC2Xik6ujrh3VaouEWDGu/NVisnszQWPv0/6PYsX62WwjSbhfgz7k3XAiG8dcDolmZGGsF4L5TKrtc7y2TZ14F50uFaLeWTBtR/sYOD37PXwBO3wmRaSAIu6pYu5cPnDbl48NZx3xdu2gz89Tfo+lwtd8fFcAPN9ppqgq3ls8cmPexd4rQqRjtsF8rBWj4ZVIy/XChlI54HZlcNKvmsBwKGJ/x3Y/db0jnAuFAEM8Y/A2G5xz9yyqnysYNh4o3tB3iVfU4xjo2cVdd2L4j19gVSXw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.004408, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Create a new variant of kvm_gmem_get_pfn(), which retains the folio lock if it returns successfully. Signed-off-by: Fuad Tabba --- include/linux/kvm_host.h | 11 +++++++++++ virt/kvm/guest_memfd.c | 19 ++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 692c01e41a18..43a157f8171a 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -2431,6 +2431,8 @@ static inline bool kvm_mem_is_private(struct kvm *kvm, gfn_t gfn) #ifdef CONFIG_KVM_PRIVATE_MEM int kvm_gmem_get_pfn(struct kvm *kvm, struct kvm_memory_slot *slot, gfn_t gfn, kvm_pfn_t *pfn, int *max_order); +int kvm_gmem_get_pfn_locked(struct kvm *kvm, struct kvm_memory_slot *slot, + gfn_t gfn, kvm_pfn_t *pfn, int *max_order); #else static inline int kvm_gmem_get_pfn(struct kvm *kvm, struct kvm_memory_slot *slot, gfn_t gfn, @@ -2439,6 +2441,15 @@ static inline int kvm_gmem_get_pfn(struct kvm *kvm, KVM_BUG_ON(1, kvm); return -EIO; } + +static inline int kvm_gmem_get_pfn_locked(struct kvm *kvm, + struct kvm_memory_slot *slot, + gfn_t gfn, kvm_pfn_t *pfn, + int *max_order) +{ + KVM_BUG_ON(1, kvm); + return -EIO; +} #endif /* CONFIG_KVM_PRIVATE_MEM */ #endif diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c index 747fe251e445..f3f4334a9ccb 100644 --- a/virt/kvm/guest_memfd.c +++ b/virt/kvm/guest_memfd.c @@ -482,8 +482,8 @@ void kvm_gmem_unbind(struct kvm_memory_slot *slot) fput(file); } -int kvm_gmem_get_pfn(struct kvm *kvm, struct kvm_memory_slot *slot, - gfn_t gfn, kvm_pfn_t *pfn, int *max_order) +int kvm_gmem_get_pfn_locked(struct kvm *kvm, struct kvm_memory_slot *slot, + gfn_t gfn, kvm_pfn_t *pfn, int *max_order) { pgoff_t index = gfn - slot->base_gfn + slot->gmem.pgoff; struct kvm_gmem *gmem; @@ -524,10 +524,23 @@ int kvm_gmem_get_pfn(struct kvm *kvm, struct kvm_memory_slot *slot, r = 0; - folio_unlock(folio); out_fput: fput(file); return r; } +EXPORT_SYMBOL_GPL(kvm_gmem_get_pfn_locked); + +int kvm_gmem_get_pfn(struct kvm *kvm, struct kvm_memory_slot *slot, + gfn_t gfn, kvm_pfn_t *pfn, int *max_order) +{ + int r; + + r = kvm_gmem_get_pfn_locked(kvm, slot, gfn, pfn, max_order); + if (r) + return r; + + unlock_page(pfn_to_page(*pfn)); + return 0; +} EXPORT_SYMBOL_GPL(kvm_gmem_get_pfn); From patchwork Thu Aug 1 09:01:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13749993 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 27073C3DA4A for ; Thu, 1 Aug 2024 09:01:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AAE586B0093; Thu, 1 Aug 2024 05:01:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A5B916B0096; Thu, 1 Aug 2024 05:01:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 811EA6B0098; Thu, 1 Aug 2024 05:01:28 -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 5C0FB6B0093 for ; Thu, 1 Aug 2024 05:01:28 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 122538095B for ; Thu, 1 Aug 2024 09:01:28 +0000 (UTC) X-FDA: 82403083056.20.BC07937 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf21.hostedemail.com (Postfix) with ESMTP id 2D89F1C001D for ; Thu, 1 Aug 2024 09:01:25 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=GKibT1fo; spf=pass (imf21.hostedemail.com: domain of 35U6rZgUKCGwdKLLKQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--tabba.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=35U6rZgUKCGwdKLLKQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--tabba.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722502811; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=31dOGsxSnS2qAkgpLgw/kAzkCwiCBaGMKDCBk/lWPaw=; b=KbdF3OYxSIgqd/ULEtwCaFiHQZwvQk1h/ILczAhYWjBg81VnqUNxRZNpPrB87wEg322Epj mrjlE+w4TEGxN6r53UxNTuBvgFen1nlRoupAlXvnBRKGhhVZLLr6AQMx5WSDFgsnMogUpi 5RBqBZ+9FzNw+dpJN6fv4k61ETq2RZk= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=GKibT1fo; spf=pass (imf21.hostedemail.com: domain of 35U6rZgUKCGwdKLLKQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--tabba.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=35U6rZgUKCGwdKLLKQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--tabba.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722502811; a=rsa-sha256; cv=none; b=mncR8df3Qw+Y9d3B43k3a1JxMIpFAIjne0K/YdVC8YCbOJhxr09z2XEAJrxTsxsdQ4/ZeK IBZ3amShHos2+t1EjFomyZBvTs8ieevqQ/fHZ8fzL9CcdbNC6MA5SvwdTDQ6z2Dvx0OZOi M4cKaVj/spiCye3c8nUI+Pgj2aK2o1Y= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-65194ea3d4dso130591897b3.0 for ; Thu, 01 Aug 2024 02:01:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722502885; x=1723107685; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=31dOGsxSnS2qAkgpLgw/kAzkCwiCBaGMKDCBk/lWPaw=; b=GKibT1foa2xquC1Km4sTOJZbgPfnMyss8lNmTXo/+u1zq+lI9Ayc/qgW1yfhkut9xk gQlyuQLxWmzpAMNbL++xb6LG9/1GXHrs1/KyqAr6dfZgIalJv6N11KHDaye7zHi8KRKm 1GeBx6S+DFUpPfDzFqXhqEC5UzLQWXahrs9tT8YM4gwJknfG6V4xMW9Mkhld2vJQ6LOX yF24pVq2XYsFDMf95n+SEye+MK8Y3hdOsuM4atlpCeWXhtI4nSFSKJ/59+iJOFi7c51n dnHL9S1ArKRXm5XUPH/z3Vz3H2gXmIvjGAkUmIDxhZlhjp0qxNCHRJdhheMqijxNOq7G LSag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722502885; x=1723107685; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=31dOGsxSnS2qAkgpLgw/kAzkCwiCBaGMKDCBk/lWPaw=; b=u5tWKSyVo83BW/39TSUTvWHeIIlt51uaWFuzXL3/aoAOygen9YnBJSh4XS9cwQU5R8 ZejC9jAaNCIMRfuTBI0lu3xlP620sWOGJLfNFseUh6TADYOfDzf6JhOaFsWh8KVRnKXI m6/wEztv11zrdq5ZBCMT50NOT9CHYGnorYlhv3Oc9DRhlfNHpZ1fmrrqU1MXNXIODADn IhL5lWRcco+IxlAiVQAF0kgwSaDcXKnIO4CsXl4HINqpDgEaxHjGc7WKOCWuTm9/6xB/ 4UG4UpSKq8VzEiAQBnly9LUQSpUw/f+zvZtEg4N96GiCFoMWqRCfrDG2Cwi3no15ueEb kUhg== X-Forwarded-Encrypted: i=1; AJvYcCWHxgGV5qKUT/LeuU+Jtc/a9l8V335Cs4rtgj2Sk3RrI/9a9S/pWcPg+5fjj+nqcBd3TCDesLAXyIwHrQKs5S+nwGs= X-Gm-Message-State: AOJu0Yw35BtSOgUDKdcTYz+Cgt0p8P2+vGmAB6hMBq44VlQN5mbims2m FmYJjwZmXkMP6GVZ40qPy2KsBX1tDZEipBKIwpyAZxRBFjKbda1XKRhKD+k+3DNcMT7mQ3vPGw= = X-Google-Smtp-Source: AGHT+IFeMtDkO9X4o1H08sPbTOZyFDUmCP10xCQXIQm4WlBnMC+GIqYzlc/fnsdt6vCtEVOetfjohOJS0A== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:a05:690c:15:b0:64a:8aec:617c with SMTP id 00721157ae682-6874580ff7emr1313617b3.0.1722502885098; Thu, 01 Aug 2024 02:01:25 -0700 (PDT) Date: Thu, 1 Aug 2024 10:01:09 +0100 In-Reply-To: <20240801090117.3841080-1-tabba@google.com> Mime-Version: 1.0 References: <20240801090117.3841080-1-tabba@google.com> X-Mailer: git-send-email 2.46.0.rc1.232.g9752f9e123-goog Message-ID: <20240801090117.3841080-3-tabba@google.com> Subject: [RFC PATCH v2 02/10] KVM: Add restricted support for mapping guestmem by the host From: Fuad Tabba To: kvm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-mm@kvack.org Cc: pbonzini@redhat.com, chenhuacai@kernel.org, mpe@ellerman.id.au, anup@brainfault.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, viro@zeniv.linux.org.uk, brauner@kernel.org, willy@infradead.org, akpm@linux-foundation.org, xiaoyao.li@intel.com, yilun.xu@intel.com, chao.p.peng@linux.intel.com, jarkko@kernel.org, amoorthy@google.com, dmatlack@google.com, yu.c.zhang@linux.intel.com, isaku.yamahata@intel.com, mic@digikod.net, vbabka@suse.cz, vannapurve@google.com, ackerleytng@google.com, mail@maciej.szmigiero.name, david@redhat.com, michael.roth@amd.com, wei.w.wang@intel.com, liam.merwick@oracle.com, isaku.yamahata@gmail.com, kirill.shutemov@linux.intel.com, suzuki.poulose@arm.com, steven.price@arm.com, quic_eberman@quicinc.com, quic_mnalajal@quicinc.com, quic_tsoni@quicinc.com, quic_svaddagi@quicinc.com, quic_cvanscha@quicinc.com, quic_pderrin@quicinc.com, quic_pheragu@quicinc.com, catalin.marinas@arm.com, james.morse@arm.com, yuzenghui@huawei.com, oliver.upton@linux.dev, maz@kernel.org, will@kernel.org, qperret@google.com, keirf@google.com, roypat@amazon.co.uk, shuah@kernel.org, hch@infradead.org, jgg@nvidia.com, rientjes@google.com, jhubbard@nvidia.com, fvdl@google.com, hughd@google.com, tabba@google.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 2D89F1C001D X-Stat-Signature: 4jzzin3c39ioa5szw8rem5kabpiciikp X-Rspam-User: X-HE-Tag: 1722502885-405559 X-HE-Meta: U2FsdGVkX19WIzqEfZEEsoBTnhSX/t0QSU6hrGDDrA/KV/A3IPIS+4bxFu1JRRQtp4cf7WrtXblvGRPxXR6u3M6MLep4Uhi00yR0nlb8WLCtAmy/XP4dQ4/XZdhCyXKh9FwG9V+4jk2WRtszjicQ3RzrU90tS3a/pzgsUPe5nnYpfcS4X5OadHmiDXFeT5ARtN4872JBcWgtkph6Wf5FvWpGOMSMdU/4SkulcLT3JJnJ1RY3v8ndT3lX6v1O63JgSCp1MF0x29hV11Eql6g+Ux07kVyr8Ap/0h+VA0amniP5X8sCKX7cuMbjMutJz6F3y5veMHK0egDWze5ph64A75ZZDXnwtdKo/4NeCoKvBin4eIjqoXQb4l0r0jBsBIlBNS4eYvh14UpvjLAu3pt7BFPGeDCIfCyCj7K0vOi8gjZEX7FA4IbyvZ+J+oYi+nayhAN86DCRJa5iDuyQJ1c3v3Z82GkW+v7z//GoLBOO/l6F5fwNQTaWT3LhAjNT9RCBQ8FnpIkrWCDqn8PU1UjpmdmmJA84xjJN4R5rW4Z19gT4zKqmTSsT3bipLSrAhFiNre4FIRGEEI6KUffg5AHkIMzqWT+nSdexG/DB9eQzpZj/K8JYf70OId502mph0ULHQUXFnJnf6u0tfFFUCoBMRGgyY2ek3JqiSFsuel6jbbiO/LhY43OgGP5QWaYTGa8kRRrFfC5kXY2usjAeS7ldBf35C6f+HQb45q1PGjiwBll1B5ZFJhFFk7dM+2S1aFuRVSY0/yaz3Nx8/SsrBQwYCHKiTj1EaqaITTwJR39Bg6i37H7ymaIaTkJGyn05aSZUrf/ZRh/86QFjVJI8ks5jSv31OWxNPwSAhnH9+PmxdwJZZ8LGUFg3TOguq/frdaTBAloTzQFpTK8hIEusxCbBiZyWS7BojPC0fiyC4UeAVfRNAKDQ5Rcy393lbiK3rvz4uT9oKDnnw/YDVkSU58J wDKvhMdO 6UzlcdPbiQHgKXxcg7pAxr+nAPQYD0cRy8/pphF2KpHNsKiojH9LvjOeDEMWg3wKZNDP2FWS0LXadjD4rlQV2DG+bSFZV5Ik0TqmhLfEI5AOWmVBkNCU9s8KedYb3r5uYvPkiNkyWJ5shiy6uK5q35EW7z17DXTQlmc9xTmHXOWVfWMXLyKBrbSvMLcnwwwqPXEtQWdLVZ/zKBAcMUuzQ36SIzsyROzDr5Ba9jpofUB2MrvWhRmUZ3RjfVOfsx9Qc4WEo7gH+P/vA/dQH8wLM5lxkOSg1BwHZ62juBGcrd1KLnXwBF6A6+UlP3w52OWWp8wcGt+s8X+LkBtunH0K2gjThmCBANoIJ9vr5KswpP2EU+wMlzkIUWW+OUmzyXk8z3mA/igszqD5/5fNZcjjKfSumudkuooYiWvFhTiERhN7qBw6BNrJ8iWzSriw5yedysJor3t6uY9vunP/ZJnAFj7xelOyH/zcEsPuV3WNSyEfnH55REyWKD3OKVCXoWROcYsSPtgvLDkeaf396NLrIKyPKcMsoghBweu2eKHrIMJUr7PY6n6F1OpttAkwRcbF9fKRGS11KtAKbfE8= 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: Add support for mmap() and fault() for guest_memfd in the host. The ability to fault in a guest page is contingent on that page being shared with the host. To track this, this patch adds a new xarray to each guest_memfd object, which tracks the mappability of guest frames. The guest_memfd PRIVATE memory attribute is not used for two reasons. First because it reflects the userspace expectation for that memory location, and therefore can be toggled by userspace. The second is, although each guest_memfd file has a 1:1 binding with a KVM instance, the plan is to allow multiple files per inode, e.g. to allow intra-host migration to a new KVM instance, without destroying guest_memfd. This new feature is gated with a new configuration option, CONFIG_KVM_PRIVATE_MEM_MAPPABLE. Signed-off-by: Fuad Tabba --- include/linux/kvm_host.h | 61 ++++++++++++++++++++ virt/kvm/Kconfig | 4 ++ virt/kvm/guest_memfd.c | 110 +++++++++++++++++++++++++++++++++++ virt/kvm/kvm_main.c | 122 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 297 insertions(+) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 43a157f8171a..ab1344327e57 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -2452,4 +2452,65 @@ static inline int kvm_gmem_get_pfn_locked(struct kvm *kvm, } #endif /* CONFIG_KVM_PRIVATE_MEM */ +#ifdef CONFIG_KVM_PRIVATE_MEM_MAPPABLE +bool kvm_gmem_is_mappable(struct kvm *kvm, gfn_t gfn, gfn_t end); +bool kvm_gmem_is_mapped(struct kvm *kvm, gfn_t start, gfn_t end); +int kvm_gmem_set_mappable(struct kvm *kvm, gfn_t start, gfn_t end); +int kvm_gmem_clear_mappable(struct kvm *kvm, gfn_t start, gfn_t end); +int kvm_slot_gmem_toggle_mappable(struct kvm_memory_slot *slot, gfn_t start, + gfn_t end, bool is_mappable); +int kvm_slot_gmem_set_mappable(struct kvm_memory_slot *slot, gfn_t start, + gfn_t end); +int kvm_slot_gmem_clear_mappable(struct kvm_memory_slot *slot, gfn_t start, + gfn_t end); +bool kvm_slot_gmem_is_mappable(struct kvm_memory_slot *slot, gfn_t gfn); +#else +static inline bool kvm_gmem_is_mappable(struct kvm *kvm, gfn_t gfn, gfn_t end) +{ + WARN_ON_ONCE(1); + return false; +} +static inline bool kvm_gmem_is_mapped(struct kvm *kvm, gfn_t start, gfn_t end) +{ + WARN_ON_ONCE(1); + return false; +} +static inline int kvm_gmem_set_mappable(struct kvm *kvm, gfn_t start, gfn_t end) +{ + WARN_ON_ONCE(1); + return -EINVAL; +} +static inline int kvm_gmem_clear_mappable(struct kvm *kvm, gfn_t start, + gfn_t end) +{ + WARN_ON_ONCE(1); + return -EINVAL; +} +static inline int kvm_slot_gmem_toggle_mappable(struct kvm_memory_slot *slot, + gfn_t start, gfn_t end, + bool is_mappable) +{ + WARN_ON_ONCE(1); + return -EINVAL; +} +static inline int kvm_slot_gmem_set_mappable(struct kvm_memory_slot *slot, + gfn_t start, gfn_t end) +{ + WARN_ON_ONCE(1); + return -EINVAL; +} +static inline int kvm_slot_gmem_clear_mappable(struct kvm_memory_slot *slot, + gfn_t start, gfn_t end) +{ + WARN_ON_ONCE(1); + return -EINVAL; +} +static inline bool kvm_slot_gmem_is_mappable(struct kvm_memory_slot *slot, + gfn_t gfn) +{ + WARN_ON_ONCE(1); + return false; +} +#endif /* CONFIG_KVM_PRIVATE_MEM_MAPPABLE */ + #endif diff --git a/virt/kvm/Kconfig b/virt/kvm/Kconfig index 29b73eedfe74..a3970c5eca7b 100644 --- a/virt/kvm/Kconfig +++ b/virt/kvm/Kconfig @@ -109,3 +109,7 @@ config KVM_GENERIC_PRIVATE_MEM select KVM_GENERIC_MEMORY_ATTRIBUTES select KVM_PRIVATE_MEM bool + +config KVM_PRIVATE_MEM_MAPPABLE + select KVM_PRIVATE_MEM + bool diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c index f3f4334a9ccb..0a1f266a16f9 100644 --- a/virt/kvm/guest_memfd.c +++ b/virt/kvm/guest_memfd.c @@ -11,6 +11,9 @@ struct kvm_gmem { struct kvm *kvm; struct xarray bindings; struct list_head entry; +#ifdef CONFIG_KVM_PRIVATE_MEM_MAPPABLE + struct xarray unmappable_gfns; +#endif }; static struct folio *kvm_gmem_get_folio(struct inode *inode, pgoff_t index) @@ -230,6 +233,11 @@ static int kvm_gmem_release(struct inode *inode, struct file *file) mutex_unlock(&kvm->slots_lock); xa_destroy(&gmem->bindings); + +#ifdef CONFIG_KVM_PRIVATE_MEM_MAPPABLE + xa_destroy(&gmem->unmappable_gfns); +#endif + kfree(gmem); kvm_put_kvm(kvm); @@ -248,7 +256,105 @@ static inline struct file *kvm_gmem_get_file(struct kvm_memory_slot *slot) return get_file_active(&slot->gmem.file); } +#ifdef CONFIG_KVM_PRIVATE_MEM_MAPPABLE +int kvm_slot_gmem_toggle_mappable(struct kvm_memory_slot *slot, gfn_t start, + gfn_t end, bool is_mappable) +{ + struct kvm_gmem *gmem = slot->gmem.file->private_data; + void *xval = is_mappable ? NULL : xa_mk_value(true); + void *r; + + r = xa_store_range(&gmem->unmappable_gfns, start, end - 1, xval, GFP_KERNEL); + + return xa_err(r); +} + +int kvm_slot_gmem_set_mappable(struct kvm_memory_slot *slot, gfn_t start, gfn_t end) +{ + return kvm_slot_gmem_toggle_mappable(slot, start, end, true); +} + +int kvm_slot_gmem_clear_mappable(struct kvm_memory_slot *slot, gfn_t start, gfn_t end) +{ + return kvm_slot_gmem_toggle_mappable(slot, start, end, false); +} + +bool kvm_slot_gmem_is_mappable(struct kvm_memory_slot *slot, gfn_t gfn) +{ + struct kvm_gmem *gmem = slot->gmem.file->private_data; + unsigned long _gfn = gfn; + + return !xa_find(&gmem->unmappable_gfns, &_gfn, ULONG_MAX, XA_PRESENT); +} + +static bool kvm_gmem_isfaultable(struct vm_fault *vmf) +{ + struct kvm_gmem *gmem = vmf->vma->vm_file->private_data; + struct inode *inode = file_inode(vmf->vma->vm_file); + pgoff_t pgoff = vmf->pgoff; + struct kvm_memory_slot *slot; + unsigned long index; + bool r = true; + + filemap_invalidate_lock(inode->i_mapping); + + xa_for_each_range(&gmem->bindings, index, slot, pgoff, pgoff) { + pgoff_t base_gfn = slot->base_gfn; + pgoff_t gfn_pgoff = slot->gmem.pgoff; + pgoff_t gfn = base_gfn + max(gfn_pgoff, pgoff) - gfn_pgoff; + + if (!kvm_slot_gmem_is_mappable(slot, gfn)) { + r = false; + break; + } + } + + filemap_invalidate_unlock(inode->i_mapping); + + return r; +} + +static vm_fault_t kvm_gmem_fault(struct vm_fault *vmf) +{ + struct folio *folio; + + folio = kvm_gmem_get_folio(file_inode(vmf->vma->vm_file), vmf->pgoff); + if (!folio) + return VM_FAULT_SIGBUS; + + if (!kvm_gmem_isfaultable(vmf)) { + folio_unlock(folio); + folio_put(folio); + return VM_FAULT_SIGBUS; + } + + vmf->page = folio_file_page(folio, vmf->pgoff); + return VM_FAULT_LOCKED; +} + +static const struct vm_operations_struct kvm_gmem_vm_ops = { + .fault = kvm_gmem_fault, +}; + +static int kvm_gmem_mmap(struct file *file, struct vm_area_struct *vma) +{ + if ((vma->vm_flags & (VM_SHARED | VM_MAYSHARE)) != + (VM_SHARED | VM_MAYSHARE)) { + return -EINVAL; + } + + file_accessed(file); + vm_flags_set(vma, VM_DONTDUMP); + vma->vm_ops = &kvm_gmem_vm_ops; + + return 0; +} +#else +#define kvm_gmem_mmap NULL +#endif /* CONFIG_KVM_PRIVATE_MEM_MAPPABLE */ + static struct file_operations kvm_gmem_fops = { + .mmap = kvm_gmem_mmap, .open = generic_file_open, .release = kvm_gmem_release, .fallocate = kvm_gmem_fallocate, @@ -369,6 +475,10 @@ static int __kvm_gmem_create(struct kvm *kvm, loff_t size, u64 flags) xa_init(&gmem->bindings); list_add(&gmem->entry, &inode->i_mapping->i_private_list); +#ifdef CONFIG_KVM_PRIVATE_MEM_MAPPABLE + xa_init(&gmem->unmappable_gfns); +#endif + fd_install(fd, file); return fd; diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 1192942aef91..f4b4498d4de6 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -3265,6 +3265,128 @@ static int next_segment(unsigned long len, int offset) return len; } +#ifdef CONFIG_KVM_PRIVATE_MEM_MAPPABLE +static bool __kvm_gmem_is_mappable(struct kvm *kvm, gfn_t start, gfn_t end) +{ + struct kvm_memslot_iter iter; + + lockdep_assert_held(&kvm->slots_lock); + + kvm_for_each_memslot_in_gfn_range(&iter, kvm_memslots(kvm), start, end) { + struct kvm_memory_slot *memslot = iter.slot; + gfn_t gfn_start, gfn_end, i; + + gfn_start = max(start, memslot->base_gfn); + gfn_end = min(end, memslot->base_gfn + memslot->npages); + if (WARN_ON_ONCE(gfn_start >= gfn_end)) + continue; + + for (i = gfn_start; i < gfn_end; i++) { + if (!kvm_slot_gmem_is_mappable(memslot, i)) + return false; + } + } + + return true; +} + +bool kvm_gmem_is_mappable(struct kvm *kvm, gfn_t start, gfn_t end) +{ + bool r; + + mutex_lock(&kvm->slots_lock); + r = __kvm_gmem_is_mappable(kvm, start, end); + mutex_unlock(&kvm->slots_lock); + + return r; +} + +static bool __kvm_gmem_is_mapped(struct kvm *kvm, gfn_t start, gfn_t end) +{ + struct kvm_memslot_iter iter; + + lockdep_assert_held(&kvm->slots_lock); + + kvm_for_each_memslot_in_gfn_range(&iter, kvm_memslots(kvm), start, end) { + struct kvm_memory_slot *memslot = iter.slot; + gfn_t gfn_start, gfn_end, i; + + gfn_start = max(start, memslot->base_gfn); + gfn_end = min(end, memslot->base_gfn + memslot->npages); + if (WARN_ON_ONCE(gfn_start >= gfn_end)) + continue; + + for (i = gfn_start; i < gfn_end; i++) { + struct page *page; + bool is_mapped; + kvm_pfn_t pfn; + + if (WARN_ON_ONCE(kvm_gmem_get_pfn_locked(kvm, memslot, i, &pfn, NULL))) + continue; + + page = pfn_to_page(pfn); + is_mapped = page_mapped(page) || page_maybe_dma_pinned(page); + unlock_page(page); + put_page(page); + + if (is_mapped) + return true; + } + } + + return false; +} + +bool kvm_gmem_is_mapped(struct kvm *kvm, gfn_t start, gfn_t end) +{ + bool r; + + mutex_lock(&kvm->slots_lock); + r = __kvm_gmem_is_mapped(kvm, start, end); + mutex_unlock(&kvm->slots_lock); + + return r; +} + +static int kvm_gmem_toggle_mappable(struct kvm *kvm, gfn_t start, gfn_t end, + bool is_mappable) +{ + struct kvm_memslot_iter iter; + int r = 0; + + mutex_lock(&kvm->slots_lock); + + kvm_for_each_memslot_in_gfn_range(&iter, kvm_memslots(kvm), start, end) { + struct kvm_memory_slot *memslot = iter.slot; + gfn_t gfn_start, gfn_end; + + gfn_start = max(start, memslot->base_gfn); + gfn_end = min(end, memslot->base_gfn + memslot->npages); + if (WARN_ON_ONCE(start >= end)) + continue; + + r = kvm_slot_gmem_toggle_mappable(memslot, gfn_start, gfn_end, is_mappable); + if (WARN_ON_ONCE(r)) + break; + } + + mutex_unlock(&kvm->slots_lock); + + return r; +} + +int kvm_gmem_set_mappable(struct kvm *kvm, gfn_t start, gfn_t end) +{ + return kvm_gmem_toggle_mappable(kvm, start, end, true); +} + +int kvm_gmem_clear_mappable(struct kvm *kvm, gfn_t start, gfn_t end) +{ + return kvm_gmem_toggle_mappable(kvm, start, end, false); +} + +#endif /* CONFIG_KVM_PRIVATE_MEM_MAPPABLE */ + /* Copy @len bytes from guest memory at '(@gfn * PAGE_SIZE) + @offset' to @data */ static int __kvm_read_guest_page(struct kvm_memory_slot *slot, gfn_t gfn, void *data, int offset, int len) From patchwork Thu Aug 1 09:01:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13749994 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 609C9C49EA1 for ; Thu, 1 Aug 2024 09:01:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E07AC6B0096; Thu, 1 Aug 2024 05:01:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DB6156B0098; Thu, 1 Aug 2024 05:01:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C0A086B0099; Thu, 1 Aug 2024 05:01:30 -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 9273C6B0096 for ; Thu, 1 Aug 2024 05:01:30 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 5060FA67A2 for ; Thu, 1 Aug 2024 09:01:30 +0000 (UTC) X-FDA: 82403083140.10.B54A2A9 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf30.hostedemail.com (Postfix) with ESMTP id 8106480012 for ; Thu, 1 Aug 2024 09:01:28 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=SsutGZ8o; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf30.hostedemail.com: domain of 3506rZgUKCG4fMNNMSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--tabba.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3506rZgUKCG4fMNNMSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--tabba.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722502825; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=r2dA+/WuAip0LraCdE4saiE0NevgxBDmZ5s6G2UnSY8=; b=Hwe0ZeKZQ6gEhX6wkgMAwATj1hR2aX0pKAd1Ehf8mMrXqFQOZHKroxT5LHWjUr7TLCUjW6 fJaw2b5VSngLuQeX6h+UX26m4ZUmhU1LZOfga8TO6nVPcVoGxXy+0n3gJUJujPYHd6i+JX UjgpQsTvkoh/d6937+RLt8Z72ayxvYo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722502825; a=rsa-sha256; cv=none; b=FfwOQXRPQX5KzCD0vqtNIVpINE+MTImhO8grfn6tSfFPZ03vmw0ekbxpFcFZKp2ea33oBe FAGc9/yPw6jFWQXGlRAWriPg7ON8gHgH5etU0xbJ3SgmhExSWZOLsNhpGFt9PGxVT/dCCI 611pNCNYYo5k2jiweYyxit5FJ4J3iig= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=SsutGZ8o; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf30.hostedemail.com: domain of 3506rZgUKCG4fMNNMSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--tabba.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3506rZgUKCG4fMNNMSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--tabba.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-664b7a67ad4so134698897b3.2 for ; Thu, 01 Aug 2024 02:01:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722502887; x=1723107687; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=r2dA+/WuAip0LraCdE4saiE0NevgxBDmZ5s6G2UnSY8=; b=SsutGZ8oTg48W2WCjUvH3igQGTzTW5jJBBa5PX9UJtze9MoMQDFyXXfi5rCKVAQ113 bikgw8wHGUul3chzBZp9N+LDwZVRgarw1VaYw/LKK1bXjgSbz6ViL5ZwHOdujHSSZnWI J22EpAMVPlYhAUuRKrAneFdI4nEsA/sWLsRJQetDwSqXwEiqZbCaJdtpy5iLGSwiGJNb gyN8sbMxblmzqQRcYTCEI9kY0ivyHZbbssviUGbJfSyS4RocsNvMLJ2VGw4X3JlFUTyE XB5pvDkT3wlaY1WeAUMWGxPsYgz04ieStwh9ETm0VPvAlS71a4U1BPlQ4jwxrsYI2CCV YOIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722502887; x=1723107687; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=r2dA+/WuAip0LraCdE4saiE0NevgxBDmZ5s6G2UnSY8=; b=cK4L8xCEQpJckESPvMZ4AD5g/iMhxdSjFJPDW0Q/DvVXo/2KDrCyQjxXUURTbs3J/l UTQre4OHSa72RCGpLqpop4yGF0Ou/bSjfY0/9PvO1+QqS+uzT7yzFI6oXssHq0imJbJb necSVQtsbi2vpnpG09fy88CUufUMTjDYyGN1hZyIvyRnVsLgvslxZGLgkJFp1/R5nU/J kOZQe4m5DqfkB/0YHG4QB85jTZ3H4OWnBP0iMS/ravdEabVRq9KyT8OhPDgDfoI72zWX u0Mn2vjgIzET229vQ4owWDBfe8Q+8S5dtAhlk1loSr5SfL5R+v3fnNOzkXiRPoJCfksb /2Hg== X-Forwarded-Encrypted: i=1; AJvYcCWW8/G8zyALOlT/PvMGD8fefxhN7j+8+mmHFm2LWQ3/Fo9Z8xtFPBa/5vrjrCPKkln6mxOvdd4e8tAyYZeDEQFnvH4= X-Gm-Message-State: AOJu0YwnFkyO4zeWJOMdBRfM3DDw+AROgB90ANjPHwcnxC7pX6Q527Yz 2WazlmfJMFHi11jIODSyYifWHGY7QBwhxs46ZvEcFraCra1aSgJkIel+5b4ONQBTLWwhD1bqBw= = X-Google-Smtp-Source: AGHT+IFTyhbnlkMzi/3eqbxm5qXZ73AAT9ul7/e/eVlxOdal7iBxLuY+Lba4cs8t3PeL8JTir4ZyTcDElQ== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:a05:690c:9e:b0:673:b39a:92ce with SMTP id 00721157ae682-6874be4e4b8mr30147b3.3.1722502887498; Thu, 01 Aug 2024 02:01:27 -0700 (PDT) Date: Thu, 1 Aug 2024 10:01:10 +0100 In-Reply-To: <20240801090117.3841080-1-tabba@google.com> Mime-Version: 1.0 References: <20240801090117.3841080-1-tabba@google.com> X-Mailer: git-send-email 2.46.0.rc1.232.g9752f9e123-goog Message-ID: <20240801090117.3841080-4-tabba@google.com> Subject: [RFC PATCH v2 03/10] KVM: Implement kvm_(read|/write)_guest_page for private memory slots From: Fuad Tabba To: kvm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-mm@kvack.org Cc: pbonzini@redhat.com, chenhuacai@kernel.org, mpe@ellerman.id.au, anup@brainfault.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, viro@zeniv.linux.org.uk, brauner@kernel.org, willy@infradead.org, akpm@linux-foundation.org, xiaoyao.li@intel.com, yilun.xu@intel.com, chao.p.peng@linux.intel.com, jarkko@kernel.org, amoorthy@google.com, dmatlack@google.com, yu.c.zhang@linux.intel.com, isaku.yamahata@intel.com, mic@digikod.net, vbabka@suse.cz, vannapurve@google.com, ackerleytng@google.com, mail@maciej.szmigiero.name, david@redhat.com, michael.roth@amd.com, wei.w.wang@intel.com, liam.merwick@oracle.com, isaku.yamahata@gmail.com, kirill.shutemov@linux.intel.com, suzuki.poulose@arm.com, steven.price@arm.com, quic_eberman@quicinc.com, quic_mnalajal@quicinc.com, quic_tsoni@quicinc.com, quic_svaddagi@quicinc.com, quic_cvanscha@quicinc.com, quic_pderrin@quicinc.com, quic_pheragu@quicinc.com, catalin.marinas@arm.com, james.morse@arm.com, yuzenghui@huawei.com, oliver.upton@linux.dev, maz@kernel.org, will@kernel.org, qperret@google.com, keirf@google.com, roypat@amazon.co.uk, shuah@kernel.org, hch@infradead.org, jgg@nvidia.com, rientjes@google.com, jhubbard@nvidia.com, fvdl@google.com, hughd@google.com, tabba@google.com X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 8106480012 X-Stat-Signature: sogccxejorj3dmj6d3dfcm915m8q4k4d X-Rspam-User: X-HE-Tag: 1722502888-718921 X-HE-Meta: U2FsdGVkX18xMJ88Pxl4g2foK8nZckb6uFaT/ckUfR/vNOA6A+vFB1FWZ7XrQR6OWEYyBxuPW9GXC3jSnuJ3nng2xFOJ6ez3nKoRKgv3r875Xl4c4whS1pnC6M0FyPvGCUYigQqyTigZx3pEhBBU+7KDBIeIdnga+MkHR9kAUT6tUxWTUeAaUCYtXNIRzv0JZ01bcCxiwX1gsh4xKeZ4Z+QGZeo6Tje7kzjtJj9FAh3uExGroL6Uz0ziiPiCGYbR6S5g5q9V1M5OlraDYfHOY4RWAME+KSVYeVj2HvQXRpKctpcti+SEiem/21fi3vT4hDa2atuAOQ254t2KAGAG5EUIstJGm8uoL153dk3dMM02RkG9vwQ906L3Zr5rHKK/Wukv91r+wLcA8N78V9zHcrbt+KVADq4FuXcl2AhnPkpd4Cxv2vPS+Z/DXgZrea75nunn+yqrX9rSIGxdA4YJRmSaxErzD/sITxE37bcAtVPEbP6PjMhIa/xSbpMC3nyMzXietO4xznFa0xwHHHsGiwDSKm6xoLn+YEP9UIJFAPo/eleRJCCEZVa+UHO/SXcSvEFQdVt2SwC2+uc5j2mJycgy6Vs+WQ6oWQJ+r1aqQjx9iTmU3vY/A7RZgIPnXl3SVw5cD8pwIr3LQzxQwoPvm8uJomm7x1O9D/bb0GifscmY/AA6dWxAMs/MTbMYYF0vl3pCnuCoZwFIzIAu3r4h/gZz89hWTo5V7jkD3FR2v8G1pkhqzd54NWY18rnbtRDWSsjTYpb72wvIuz7TGLRjRlLJsQ9eSLRUAHqhumxN50hG3jNgzlP6/bkyVYG0GgTn5cCJ34mSLZBpFfNT1BsMJr+qYfANfSefXTcBPS1yrCDbe5dHBEqJCP5+8oc3V9E6hcB2ozSZ5T+PcblSn9doPPBVRfaPo3aap7j420yw+OyWwNlURkTO71SUc8lYJi4/23FJr7gAkfaRByB/A6o rzx9ToVf 6l0835YsZm36LB9KBsGoky6QJLnPbJC3niaH2p22EZPZnxITdgPgN9Akueu9WAixe4iiFAssYr68QFBzfYZ831NpmIpIzyQ8MMeBZAbxx2Rt4qJP9KhMSR/TclC4xB0FogohRB/iBOUDpskUj6ZFvpc0xkSJMQrnMsT3YKXyNMLDV502mm9lGNxKPSHAWlU1IxuF0Y1D+snvd68Q7vsbj8QDDBIZ/shHMP71DrgyDUf+Ks4B1tv46p0FwilcEIdrkc7+Ioew8G4Sa7vu/Qt3VRBRph3xXPoAb/RhZjvcyeq8Lp0w77CcEQu4Iza42/1NBwc2ZhQ0E2zDDQHAGTtqYpke68nTwA8KpdvNHQmSRyW7XbGtD96CIT2XG7c4kynQyqMJzNF+FGnvpJC3+X/py+9f3+NbDzUmtXm46i/x0Ec0z18NRKI9qG+s4HXwVprMd8mTav+NNJ+weUvxMBCS28SAAOxt33mib0pnFAuRixCg9rMuSXS7kClAdo84b93CSN9V4r0l7XQMq4VxGmUyWTRguTd10bpVjd0L3ymH8/V1RBrW15/gaKWjJ1WwcBZgIJXKDb9aCvBRlunOZsH26n8uwNxpO9G0HpHId9Vgh9wN4aAcGsNt/FH0WLA== 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: Make __kvm_read_guest_page/__kvm_write_guest_page capable of accessing guest memory if no userspace address is available. Moreover, check that the memory being accessed is shared with the host before attempting the access. KVM at the host might need to access shared memory that is not mapped in the host userspace but is in fact shared with the host, e.g., when accounting for stolen time. This allows the access without relying on the slot's userspace_addr being set. This does not circumvent protection, since the access is only attempted if the memory is mappable by the host, which implies shareability. Signed-off-by: Fuad Tabba --- virt/kvm/kvm_main.c | 127 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 111 insertions(+), 16 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index f4b4498d4de6..ec6255c7325e 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -3385,20 +3385,108 @@ int kvm_gmem_clear_mappable(struct kvm *kvm, gfn_t start, gfn_t end) return kvm_gmem_toggle_mappable(kvm, start, end, false); } +static int __kvm_read_private_guest_page(struct kvm *kvm, + struct kvm_memory_slot *slot, + gfn_t gfn, void *data, int offset, + int len) +{ + struct page *page; + u64 pfn; + int r = 0; + + if (size_add(offset, len) > PAGE_SIZE) + return -E2BIG; + + mutex_lock(&kvm->slots_lock); + + if (!__kvm_gmem_is_mappable(kvm, gfn, gfn + 1)) { + r = -EPERM; + goto unlock; + } + + r = kvm_gmem_get_pfn_locked(kvm, slot, gfn, &pfn, NULL); + if (r) + goto unlock; + + page = pfn_to_page(pfn); + memcpy(data, page_address(page) + offset, len); + unlock_page(page); + kvm_release_pfn_clean(pfn); +unlock: + mutex_unlock(&kvm->slots_lock); + + return r; +} + +static int __kvm_write_private_guest_page(struct kvm *kvm, + struct kvm_memory_slot *slot, + gfn_t gfn, const void *data, + int offset, int len) +{ + struct page *page; + u64 pfn; + int r = 0; + + if (size_add(offset, len) > PAGE_SIZE) + return -E2BIG; + + mutex_lock(&kvm->slots_lock); + + if (!__kvm_gmem_is_mappable(kvm, gfn, gfn + 1)) { + r = -EPERM; + goto unlock; + } + + r = kvm_gmem_get_pfn_locked(kvm, slot, gfn, &pfn, NULL); + if (r) + goto unlock; + + page = pfn_to_page(pfn); + memcpy(page_address(page) + offset, data, len); + unlock_page(page); + kvm_release_pfn_dirty(pfn); +unlock: + mutex_unlock(&kvm->slots_lock); + + return r; +} +#else +static int __kvm_read_private_guest_page(struct kvm *kvm, + struct kvm_memory_slot *slot, + gfn_t gfn, void *data, int offset, + int len) +{ + WARN_ON_ONCE(1); + return -EIO; +} + +static int __kvm_write_private_guest_page(struct kvm *kvm, + struct kvm_memory_slot *slot, + gfn_t gfn, const void *data, + int offset, int len) +{ + WARN_ON_ONCE(1); + return -EIO; +} #endif /* CONFIG_KVM_PRIVATE_MEM_MAPPABLE */ /* Copy @len bytes from guest memory at '(@gfn * PAGE_SIZE) + @offset' to @data */ -static int __kvm_read_guest_page(struct kvm_memory_slot *slot, gfn_t gfn, - void *data, int offset, int len) + +static int __kvm_read_guest_page(struct kvm *kvm, struct kvm_memory_slot *slot, + gfn_t gfn, void *data, int offset, int len) { - int r; unsigned long addr; + if (IS_ENABLED(CONFIG_KVM_PRIVATE_MEM_MAPPABLE) && + kvm_slot_can_be_private(slot)) { + return __kvm_read_private_guest_page(kvm, slot, gfn, data, + offset, len); + } + addr = gfn_to_hva_memslot_prot(slot, gfn, NULL); if (kvm_is_error_hva(addr)) return -EFAULT; - r = __copy_from_user(data, (void __user *)addr + offset, len); - if (r) + if (__copy_from_user(data, (void __user *)addr + offset, len)) return -EFAULT; return 0; } @@ -3408,7 +3496,7 @@ int kvm_read_guest_page(struct kvm *kvm, gfn_t gfn, void *data, int offset, { struct kvm_memory_slot *slot = gfn_to_memslot(kvm, gfn); - return __kvm_read_guest_page(slot, gfn, data, offset, len); + return __kvm_read_guest_page(kvm, slot, gfn, data, offset, len); } EXPORT_SYMBOL_GPL(kvm_read_guest_page); @@ -3417,7 +3505,7 @@ int kvm_vcpu_read_guest_page(struct kvm_vcpu *vcpu, gfn_t gfn, void *data, { struct kvm_memory_slot *slot = kvm_vcpu_gfn_to_memslot(vcpu, gfn); - return __kvm_read_guest_page(slot, gfn, data, offset, len); + return __kvm_read_guest_page(vcpu->kvm, slot, gfn, data, offset, len); } EXPORT_SYMBOL_GPL(kvm_vcpu_read_guest_page); @@ -3492,17 +3580,24 @@ EXPORT_SYMBOL_GPL(kvm_vcpu_read_guest_atomic); /* Copy @len bytes from @data into guest memory at '(@gfn * PAGE_SIZE) + @offset' */ static int __kvm_write_guest_page(struct kvm *kvm, struct kvm_memory_slot *memslot, gfn_t gfn, - const void *data, int offset, int len) + const void *data, int offset, int len) { - int r; - unsigned long addr; + if (IS_ENABLED(CONFIG_KVM_PRIVATE_MEM_MAPPABLE) && + kvm_slot_can_be_private(memslot)) { + int r = __kvm_write_private_guest_page(kvm, memslot, gfn, data, + offset, len); + + if (r) + return r; + } else { + unsigned long addr = gfn_to_hva_memslot(memslot, gfn); + + if (kvm_is_error_hva(addr)) + return -EFAULT; + if (__copy_to_user((void __user *)addr + offset, data, len)) + return -EFAULT; + } - addr = gfn_to_hva_memslot(memslot, gfn); - if (kvm_is_error_hva(addr)) - return -EFAULT; - r = __copy_to_user((void __user *)addr + offset, data, len); - if (r) - return -EFAULT; mark_page_dirty_in_slot(kvm, memslot, gfn); return 0; } From patchwork Thu Aug 1 09:01:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13749995 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 84C7AC3DA64 for ; Thu, 1 Aug 2024 09:01:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 443206B0098; Thu, 1 Aug 2024 05:01:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3D22D6B0099; Thu, 1 Aug 2024 05:01:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 245E66B009A; Thu, 1 Aug 2024 05:01:33 -0400 (EDT) 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 F353D6B0098 for ; Thu, 1 Aug 2024 05:01:32 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9F342409B0 for ; Thu, 1 Aug 2024 09:01:32 +0000 (UTC) X-FDA: 82403083224.27.CCD0C89 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf02.hostedemail.com (Postfix) with ESMTP id DC63880023 for ; Thu, 1 Aug 2024 09:01:30 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=RzUX4vU7; spf=pass (imf02.hostedemail.com: domain of 36U6rZgUKCHAhOPPOUccUZS.QcaZWbil-aaYjOQY.cfU@flex--tabba.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=36U6rZgUKCHAhOPPOUccUZS.QcaZWbil-aaYjOQY.cfU@flex--tabba.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722502835; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=LPYjxi2NpHlLCCCycghuduPbRm3K8NiftdQ2Nx+A00o=; b=WkeKwWP+VhHilaHNpEM7E18lBwMU1iCywZE7h3kNCSDgpE+Km/rN96NY1qtNxXVSgQiBDw h4of4fU7MVcCJjV9S0Q3KQLBjyU/cjCeP/lWffTQeQvUIr7b1SjKYL12onWt8+v41MvmPh bNBs8ZprIHX1U7gE3jwOSHSJkmKWtTI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722502835; a=rsa-sha256; cv=none; b=KbLN8urFUNr8QKvD2A365Cdt0QR6C5nkhZFkpUgGtsik+Kmvn+mTVwFWx7GAeBnDsvvzLX TjzVxmiqFe3lxblmd2Y8aeQgBV6WgBA43W2IEyeDrnP3aojadvJhrlMbhrvxXxGGPtfG3t 9pkWWqUljzWyDDiznHmBVN1Qfr+eCIw= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=RzUX4vU7; spf=pass (imf02.hostedemail.com: domain of 36U6rZgUKCHAhOPPOUccUZS.QcaZWbil-aaYjOQY.cfU@flex--tabba.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=36U6rZgUKCHAhOPPOUccUZS.QcaZWbil-aaYjOQY.cfU@flex--tabba.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-66c0f57549fso152656857b3.0 for ; Thu, 01 Aug 2024 02:01:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722502890; x=1723107690; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=LPYjxi2NpHlLCCCycghuduPbRm3K8NiftdQ2Nx+A00o=; b=RzUX4vU7R6umJ7I6QH7jvcRlTOHrEj2iWpdfcMRaf2dUYE/0kD8AgF61oaSrkevxgS juMO0cTcQYedxT7xCJVKbQspTUHGKQ+JyBKnV3///fw0zx3HO6fFGJDuA6vrFc4MnBw6 IEYTvqxN6w7Q0gmKxN8vyWWGp+0V0KA4JX2vMlNoE51mcr719gwoPtUzWsVT+TIs/PD7 DRrLzTlpvzZgTc7YonfbB+sF3ZnsLVTVPQWqraMeKWDFjI+okgBQEZOuCNtxGcfEr8nI gcrFJ3vj35eiiEDEdh6k/C2c6BpUW87Zhd4pg14/Pjw5DEhrQoTva6Uk8WvQCNwj6XaV YQNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722502890; x=1723107690; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LPYjxi2NpHlLCCCycghuduPbRm3K8NiftdQ2Nx+A00o=; b=YLoZz2sN14Tn1BPpio9lh2dmBeLdIKrLL67wpZd73CQpI2BDknqg83Xh70QOs1wwsh ybOMLJe13/QwYTDZHh5VsH9pOBEflP5lh052tjz3tOmCBBPatRD7aHMctNBeNV02n5Ij n8GsBMY4/BYM+L2CDt8lBGFu5Wd/MvcsyNDasbekqCaWO2e8MkfUk44HbunKiHtLK4Fq vi6EYhjskijKvVcKyNpc3XGmrUVRl3o1FydACJqrXHA+SLQ0c3ExpO43WeC5iFFfWysY hqwzdzExumkfl0L55ZLUiM884G6jNFCfdj3zz5Omt5nNfmQ0RHCckccDufyR24+/Zlhc zkmg== X-Forwarded-Encrypted: i=1; AJvYcCV5rTfkRdzYNnJ9eYiHlCd/Yw7wWvtfy1kasSAArhD3XT+zu9CxeWBJjFEcc5s5CNoUmF0bLBu95A==@kvack.org X-Gm-Message-State: AOJu0Yynh9zffxptYKy8FIY1mvMx+phhWkZwNt0j2ZZBXPN5oSqXw9ur BPYuse8hrSl21zRZdkwAzZs2zxq2KQUqB/6teg82zYQrQywLuVfJBNHUUuinhf3cMVWNTfNtvw= = X-Google-Smtp-Source: AGHT+IEWXtT3G1kPV2U5ozw0QmNThPZWLC3X0cJFXxT6qwOkPcf9RWWDopByOJxRGSqLytT/Up6QyZXMSQ== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:a05:690c:9e:b0:673:b39a:92ce with SMTP id 00721157ae682-6874be4e4b8mr30247b3.3.1722502889731; Thu, 01 Aug 2024 02:01:29 -0700 (PDT) Date: Thu, 1 Aug 2024 10:01:11 +0100 In-Reply-To: <20240801090117.3841080-1-tabba@google.com> Mime-Version: 1.0 References: <20240801090117.3841080-1-tabba@google.com> X-Mailer: git-send-email 2.46.0.rc1.232.g9752f9e123-goog Message-ID: <20240801090117.3841080-5-tabba@google.com> Subject: [RFC PATCH v2 04/10] KVM: Add KVM capability to check if guest_memfd can be mapped by the host From: Fuad Tabba To: kvm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-mm@kvack.org Cc: pbonzini@redhat.com, chenhuacai@kernel.org, mpe@ellerman.id.au, anup@brainfault.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, viro@zeniv.linux.org.uk, brauner@kernel.org, willy@infradead.org, akpm@linux-foundation.org, xiaoyao.li@intel.com, yilun.xu@intel.com, chao.p.peng@linux.intel.com, jarkko@kernel.org, amoorthy@google.com, dmatlack@google.com, yu.c.zhang@linux.intel.com, isaku.yamahata@intel.com, mic@digikod.net, vbabka@suse.cz, vannapurve@google.com, ackerleytng@google.com, mail@maciej.szmigiero.name, david@redhat.com, michael.roth@amd.com, wei.w.wang@intel.com, liam.merwick@oracle.com, isaku.yamahata@gmail.com, kirill.shutemov@linux.intel.com, suzuki.poulose@arm.com, steven.price@arm.com, quic_eberman@quicinc.com, quic_mnalajal@quicinc.com, quic_tsoni@quicinc.com, quic_svaddagi@quicinc.com, quic_cvanscha@quicinc.com, quic_pderrin@quicinc.com, quic_pheragu@quicinc.com, catalin.marinas@arm.com, james.morse@arm.com, yuzenghui@huawei.com, oliver.upton@linux.dev, maz@kernel.org, will@kernel.org, qperret@google.com, keirf@google.com, roypat@amazon.co.uk, shuah@kernel.org, hch@infradead.org, jgg@nvidia.com, rientjes@google.com, jhubbard@nvidia.com, fvdl@google.com, hughd@google.com, tabba@google.com X-Rspamd-Queue-Id: DC63880023 X-Stat-Signature: dhe78aowpjsdp1n4jcbizqmybsg6b854 X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1722502890-750336 X-HE-Meta: U2FsdGVkX1/aUagP1NUxfos37gL+lbZT1QwNmjw+C1+uCZOkHvdcUANzoA/fpciT8caZZheTji+us7UIjp8La1DfIJojO7CF003uqIZMiCtIpUXLUBRsfsghRVLCBGEGdS6E9a5r7WHAxi6KCQTnX5hic7YFLjLuduMTtbjaaDwozEd3Fj9gkKKnyUgf6p0WtKeLeCS3dftnMbmSXX+cjoA6DCoWur6dUCyXUKzgYS9euNfEwz0y6+IQ0iIq96tkl7UiJtei816RP9jEwx2p2NLs8OLtxrBJ6YgkEttloTOLF7pDkDnQzXjAy6hxbp+LWUpH32bE7skCCZ+izYSaPY53LUptC5y7z2AY3jzAa6Y8oX6JsKFq8sfpM/NqKkSbZ72CgIwRoFbUjK+i/SMUnyy/+3l5dXwzCaBCmz8/WLDCSspaD7HMSnTflOsgGadQ/kN5dl0y92Wb/3UTzdbG20ugmzr9RnQNW3R0dYqAiTJCbK4ObIIlcdfB3LyxXZsMsfNuEuqUqUPlWN/PH2liG24yMXkS458GAB/EmMNi7uBjfo9z0R3+ohtcYYwWPdCvIs6Fi22NoWply9Upx9wSpzIleUdt4uMid8HgU3gBHBaPKzC6f+yymmp5L+zOLaZqHXZuSAyn342G/Z9YltIdsk2xUoDqx3UVvzyrV751M4lxLfDGGEuwv7FwlSspPixG5b3hGiX1ebri3FiLpgPOoDSjIhFWR3qBRODoLFHJrzbLCFJbV1qsZBRHLAbH/6gLzAavm+CoAffWOS9M22Uqp974oo0ORzBQed9EhOa9EWI96IViDWDt/UfjAxoeMb/V44PNTnOizOZRg+qk37n4YXLocPzGBQsf8Z/SO0PrWJinFaGnPxohH8UGbSEVCQz4Td6VrZVp/fIOE4Pa86Hs7dgr9HOOQ54w2U1Gzu6jxl+icSWSELZJwtCGPaZwqDtdRTfYSiEGHlU4XYzOYkk WpiB5q8F XUGi+CvH87+SfqM7JucQexl7rMwx+qIbb3Qeo+coZ3rLw2wSsu/LRA668SKokVAF8Hd9u4a5QJhDst44rExp4XBz+AXkImksX7W2sKE+eW1acsCDPxrWrqu5sAQIm6Cteab2t8msIm/0B3hxZ0/bgLoek2S1kMkVGZ1u8lIaYM8CS5ujoWjZHZbD3uJOU95ROG0t6plv+kP5ZYORIBU6xp6M4p1OANOCdMZZcB8OBpcGy533XS57HVcwrqBBYNX4olQ/u7jNyzDGCIl8J1ZehPnjbqSK86L5tntE8Lp3/Drr4DYr1ca4Y+e7yQvHwrlBXxI25LA3e9POJxejmLP1+kSZSq63DbDA61XVnjIzqjK5qebYlQh9Lbt5ENJ/3kfeLQjZ4MJF372LYBcfVanxyQaAe0FpFOxPr3gm3fzy9ljRxzwCN2BA+uJQIMjZJeh8cJrZXohEkn0vGgP7XzAt+Ojrzv3/s4BOBMpb7yEtLc1Uo61HSTMhjXpdMTT2LRhNuv50sax3JwdnHuIcBl0UAbctPGYlR1T/95jUmEbHi67VwyFYzJ/Dp3OIyYDYOpKppZV6xNU5BtJFJjosDJ1YUxX6DRjO5D+nX79GLUxzWSQCYrNt4f9pKNDEP4viBsqKKCbLB62/wSujt7dy+WlCWBEnJsw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000019, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add the KVM capability KVM_CAP_GUEST_MEMFD_MAPPABLE, which is true if mapping guest memory is supported by the host. Signed-off-by: Fuad Tabba --- include/uapi/linux/kvm.h | 3 ++- virt/kvm/kvm_main.c | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index d03842abae57..783d0c3f4cb1 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -916,7 +916,8 @@ struct kvm_enable_cap { #define KVM_CAP_MEMORY_FAULT_INFO 232 #define KVM_CAP_MEMORY_ATTRIBUTES 233 #define KVM_CAP_GUEST_MEMFD 234 -#define KVM_CAP_VM_TYPES 235 +#define KVM_CAP_GUEST_MEMFD_MAPPABLE 235 +#define KVM_CAP_VM_TYPES 236 struct kvm_irq_routing_irqchip { __u32 irqchip; diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index ec6255c7325e..485c39fc373c 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -5077,6 +5077,10 @@ static int kvm_vm_ioctl_check_extension_generic(struct kvm *kvm, long arg) #ifdef CONFIG_KVM_PRIVATE_MEM case KVM_CAP_GUEST_MEMFD: return !kvm || kvm_arch_has_private_mem(kvm); +#endif +#ifdef CONFIG_KVM_PRIVATE_MEM_MAPPABLE + case KVM_CAP_GUEST_MEMFD_MAPPABLE: + return !kvm || kvm_arch_has_private_mem(kvm); #endif default: break; From patchwork Thu Aug 1 09:01:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13749996 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 0D958C3DA64 for ; Thu, 1 Aug 2024 09:01:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4BAC66B008C; Thu, 1 Aug 2024 05:01:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3CC236B009A; Thu, 1 Aug 2024 05:01:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 294216B009B; Thu, 1 Aug 2024 05:01:36 -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 076246B008C for ; Thu, 1 Aug 2024 05:01:36 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 7F4DF1A092C for ; Thu, 1 Aug 2024 09:01:35 +0000 (UTC) X-FDA: 82403083350.29.B8C8134 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf27.hostedemail.com (Postfix) with ESMTP id B2B0A40027 for ; Thu, 1 Aug 2024 09:01:33 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=XyyX0Xve; spf=pass (imf27.hostedemail.com: domain of 37E6rZgUKCHMkRSSRXffXcV.TfdcZelo-ddbmRTb.fiX@flex--tabba.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=37E6rZgUKCHMkRSSRXffXcV.TfdcZelo-ddbmRTb.fiX@flex--tabba.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722502836; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=FenZNVmro9JWmRf8yJhfaxf1ruU6PeQcDA6Tq5ucplA=; b=YncM5uu8CJz3nxo7aqEDChD9iV54ricAVtCFwWZD/bNu2FqDRE7Bubaf8omx+5VgvhQKbZ s38c1qNDqUBSd0IT1F4yogoTBm6bdXZASGyMNod7rnm2VcwtjmhwqH0DLD5wvpWI6HY6iZ 6pE1VwFCBfhemuLd4jpF9PRaJqrCLYU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722502836; a=rsa-sha256; cv=none; b=Z/YC9pA+8y8z/6IGVU+uBHGxzHLF0ltesxbhgrMpPbhUm7dniZSBhKJhenmnsTAnwSE4bo DhgJTAEhv7+XqzyB3kTzPIiMVbNSyiaQpIFVrZHAW17q6avqkoMSKA2b07uAS0wUKla+f6 LruBpas5MPfabqwtBkS2AztYsOyxzlg= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=XyyX0Xve; spf=pass (imf27.hostedemail.com: domain of 37E6rZgUKCHMkRSSRXffXcV.TfdcZelo-ddbmRTb.fiX@flex--tabba.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=37E6rZgUKCHMkRSSRXffXcV.TfdcZelo-ddbmRTb.fiX@flex--tabba.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-665a6dd38c8so130277657b3.1 for ; Thu, 01 Aug 2024 02:01:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722502893; x=1723107693; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=FenZNVmro9JWmRf8yJhfaxf1ruU6PeQcDA6Tq5ucplA=; b=XyyX0XveyXQg7256dR5hY1bKkvN7QtNME6bpJNV5q8+QWb7FE7/g6eikSxPKmDKShS T8fwjlXmzqz21vDJt2v0NVXaTdWidtm6QdPO4kYRPeoGrlclS+kl2lRosm/dTmgvKu8+ LfUpF2nS2t9FXYrkSsZMRgzFh+lqCFH1N+dQ1RNrDSvPE64BS8CJbP3cpol4ByUE4Nbe 7Lt3TqYoS52hOqk28sKOPhchZSbab3a22PL6umwtRESe/4BlyXnS/Ww3dekREqjeVPBX 53mziA4XDzXzzpYTugu+qMB4wLoYj4krJp4T/8TSuVzVL8eK7WG618SKtINVC5Kz4p+c JSsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722502893; x=1723107693; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=FenZNVmro9JWmRf8yJhfaxf1ruU6PeQcDA6Tq5ucplA=; b=OoISZTiIUVTtJeMlB81P7Cgo/8dgTayXCsm09R17U3/Hc0i2Yl8ngbVEeQiRMIc+Rl 7CVqMnds4VFtfulrcrXY6t+zalZ33o3riwxs28E/V/Hl5xq4z2r4KldXQqAxZ9lpD4IZ 5pK8ZCJVnbeS2daFoq2V+a3ELd6QwGvQhrvrWyyEzG4gucds9Aa3xNNnyUpypNdMxycA o6QSt/84NHn2eOGieG8nnM9GTH5try15svyUZyiOP2CulVbIx3g5ayC8fuXOTE7QB/Gh KiBktIyg4gs5iewrFsmVOZ9qnuqka6YUTPio+J7lxIXiWFY2GenBRMQYHPibV9IvnIMK M8Yw== X-Forwarded-Encrypted: i=1; AJvYcCWTTIfSLrK+p9A8752nxlBFKMUm0njOLrjgrWBfKQluoos60tJ3MyD40bL8g4xt5e/Ymorc+DjeN83QeSbI2Z4dods= X-Gm-Message-State: AOJu0Yxnsebsk5BLQzbJIimfKu2UBICrU+KTYgGZek+TqdfSQV7Yo1W6 EE9e/peTe3yyj4sY+PTwzP9vtGH/IDd5fKo+DpkYh+RB+0Ete1WbWaXNR1bDuv11jtEiTqawlA= = X-Google-Smtp-Source: AGHT+IGm9QckLnDbVxc2uajSqqnHpYUpgzy1Qib76hzzsjZLg4j1Inen+nQBahz4WB8vSdsSSS9dwIaeEA== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:a05:690c:dcf:b0:665:a4a4:57c1 with SMTP id 00721157ae682-6874a9ec608mr269487b3.2.1722502892571; Thu, 01 Aug 2024 02:01:32 -0700 (PDT) Date: Thu, 1 Aug 2024 10:01:12 +0100 In-Reply-To: <20240801090117.3841080-1-tabba@google.com> Mime-Version: 1.0 References: <20240801090117.3841080-1-tabba@google.com> X-Mailer: git-send-email 2.46.0.rc1.232.g9752f9e123-goog Message-ID: <20240801090117.3841080-6-tabba@google.com> Subject: [RFC PATCH v2 05/10] KVM: selftests: guest_memfd mmap() test when mapping is allowed From: Fuad Tabba To: kvm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-mm@kvack.org Cc: pbonzini@redhat.com, chenhuacai@kernel.org, mpe@ellerman.id.au, anup@brainfault.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, viro@zeniv.linux.org.uk, brauner@kernel.org, willy@infradead.org, akpm@linux-foundation.org, xiaoyao.li@intel.com, yilun.xu@intel.com, chao.p.peng@linux.intel.com, jarkko@kernel.org, amoorthy@google.com, dmatlack@google.com, yu.c.zhang@linux.intel.com, isaku.yamahata@intel.com, mic@digikod.net, vbabka@suse.cz, vannapurve@google.com, ackerleytng@google.com, mail@maciej.szmigiero.name, david@redhat.com, michael.roth@amd.com, wei.w.wang@intel.com, liam.merwick@oracle.com, isaku.yamahata@gmail.com, kirill.shutemov@linux.intel.com, suzuki.poulose@arm.com, steven.price@arm.com, quic_eberman@quicinc.com, quic_mnalajal@quicinc.com, quic_tsoni@quicinc.com, quic_svaddagi@quicinc.com, quic_cvanscha@quicinc.com, quic_pderrin@quicinc.com, quic_pheragu@quicinc.com, catalin.marinas@arm.com, james.morse@arm.com, yuzenghui@huawei.com, oliver.upton@linux.dev, maz@kernel.org, will@kernel.org, qperret@google.com, keirf@google.com, roypat@amazon.co.uk, shuah@kernel.org, hch@infradead.org, jgg@nvidia.com, rientjes@google.com, jhubbard@nvidia.com, fvdl@google.com, hughd@google.com, tabba@google.com X-Stat-Signature: 3zw9bwrhs4a385gkbp1p57ubw8idbpof X-Rspamd-Queue-Id: B2B0A40027 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1722502893-822629 X-HE-Meta: U2FsdGVkX18WbvRK9ZDsTyeUhkRyLNyRkVaIugTRGx4NC+nPuPeeaHDRs62U4GjKoMNU/R2ak6gPEb7vCi5Y6qFFm0fHA4h40w4AnKckU+n8B/RRsN6L0WlBkXyUZZ3J7vg/vrSgzSjDre4YUtizZiZ/DZ0jZzffJ6rd8ghoA9sb17Nk301uHofoVQ9LW0fFR0W8x+HGHxc3O848sPeQ5aNx2NTvViXL1BTnVhI9snWup1HVvLgLFrHaj1QEqAmOhRYKGy6dkAufA1FBBAHeE98ynybRxJA/oYA+E+NlKJiIWK01EprPICfwLj2oTJza5XaCClNFmymDm119+WH0Hucb0/lpWjlTcglhOg6WDxSNt3eoJEmrhSQTSvhe/5Sw4eOKR/SbEFxXuHn+OlkmBseN/TNReKZ/Pe4EixwoF+nvHnXveLyNcFJCi2c7af7vt/P82ah+I4ltK7HqbG9nJQFVZrw7nfe67ZZCeriXAnNCChRnN6CS6i8QbGccZ02k5HRXaHm+ACehoH/dgnSVmA98M/4hWp3L0rlkva3/MFo4Aa35io74xQSAlH2+xw7rnthge7JWl5nYE4yzer9cdxHLUCQpIxOBf++gEjYjNetnc7PGLoE0EiAEijj3tmYgDWRMRM0G/wVaXWOjUjrviAiiwAR41y1hXlkw9yyQA42/FWExP2AiRRKpI6Z3Huj2XoXCfOukxcQhyIuosvemKzYdTcF8v/VBQRhWag2hromEvUzAq3W/+NygLmtNWOugJ3RHlYeayFLyuhzH7nd3CF1TUHkGxW/HnMoR+4D8aZP3JkUNq4uEG4PuE2W/WvVZYxiRr1ijvaZz7dwoiqcIeQrDb3uq3PZCxKHaNOx6ETvaVxYn5pmZCtFM4fpYvAXxXgxpPcFbmwISkziS3DRSf1xdbHFfXZEqTq0CqJIEcX9BBZrGczcTp7BjQ53KHo0cdvySvlvpcEvqqB38x+4 MKuIwiFk SDV67GmGyRalHtcOqaoPePIwbQI5NzhHMLHUL0nziDyBYlBQ6u1fxAfycD2agQZnXv979LoexIaM6xm5Jczkb5r0NUZJxWX2PKWTKIbMTZYtzbghmp+K+IzIGgZWISe3SpUnMFC9f5rfLFgYZdJTjiI9jn238ftWk86ruQgT8SgD+5QXOvLIco2UsY2uiE3REyDhyTYd6AphnltLfIUJKCFYj99+PNr+9K9wCCAcySnNqyiDBc/NMPTIonnSK8MSKPf6CUUc+7ABBp396xAmmP5gjeH36f8TJwnIVt+uKy/rwvgdVlT3vCFZc01+PGzbvqiPRaGk4UT14HFlRM7VvkPTCETvd03gOqTzmd3Nk/IFZsrvlxiN7Yjjj2dAZnOFnoRztLw3+4HWHPMYDv3/TIVb+PXWUiuaILYO4Ds89euRi0DRH7QG2woSnacGfURZLruwb10QbKotE/js52tUj9PTBzJFA+OJ/1N3lfU9MZgSD/d9P4BCQwFyXidTkzaVUGJPP+pgQbJmV+ylcEBBJ8xIHH0wMoo9lgez2pTys2/f5Whq5BWBvef//nsWXD3PXFk5/Z9XpVLu6nN/3bBpEs+x6mDpkO7sQ+HQXbdzPZien/TRhjLZW8nPgqg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000010, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Expand the guest_memfd selftests to include testing mapping guest memory if the capability is supported, and that still checks that memory is not mappable if the capability isn't supported. Also, build the guest_memfd selftest for aarch64. Signed-off-by: Fuad Tabba --- tools/testing/selftests/kvm/Makefile | 1 + .../testing/selftests/kvm/guest_memfd_test.c | 47 ++++++++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile index ac280dcba996..fb63f7e956d4 100644 --- a/tools/testing/selftests/kvm/Makefile +++ b/tools/testing/selftests/kvm/Makefile @@ -166,6 +166,7 @@ TEST_GEN_PROGS_aarch64 += arch_timer TEST_GEN_PROGS_aarch64 += demand_paging_test TEST_GEN_PROGS_aarch64 += dirty_log_test TEST_GEN_PROGS_aarch64 += dirty_log_perf_test +TEST_GEN_PROGS_aarch64 += guest_memfd_test TEST_GEN_PROGS_aarch64 += guest_print_test TEST_GEN_PROGS_aarch64 += get-reg-list TEST_GEN_PROGS_aarch64 += kvm_create_max_vcpus diff --git a/tools/testing/selftests/kvm/guest_memfd_test.c b/tools/testing/selftests/kvm/guest_memfd_test.c index ba0c8e996035..c6bb2be5b6e2 100644 --- a/tools/testing/selftests/kvm/guest_memfd_test.c +++ b/tools/testing/selftests/kvm/guest_memfd_test.c @@ -34,12 +34,55 @@ static void test_file_read_write(int fd) "pwrite on a guest_mem fd should fail"); } -static void test_mmap(int fd, size_t page_size) +static void test_mmap_allowed(int fd, size_t total_size) { + size_t page_size = getpagesize(); + char *mem; + int ret; + int i; + + mem = mmap(NULL, total_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + TEST_ASSERT(mem != MAP_FAILED, "mmaping() guest memory should pass."); + + memset(mem, 0xaa, total_size); + for (i = 0; i < total_size; i++) + TEST_ASSERT_EQ(mem[i], 0xaa); + + ret = fallocate(fd, FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE, 0, + page_size); + TEST_ASSERT(!ret, "fallocate the first page should succeed"); + + for (i = 0; i < page_size; i++) + TEST_ASSERT_EQ(mem[i], 0x00); + for (; i < total_size; i++) + TEST_ASSERT_EQ(mem[i], 0xaa); + + memset(mem, 0xaa, total_size); + for (i = 0; i < total_size; i++) + TEST_ASSERT_EQ(mem[i], 0xaa); + + ret = munmap(mem, total_size); + TEST_ASSERT(!ret, "munmap should succeed"); +} + +static void test_mmap_denied(int fd, size_t total_size) +{ + size_t page_size = getpagesize(); char *mem; mem = mmap(NULL, page_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); TEST_ASSERT_EQ(mem, MAP_FAILED); + + mem = mmap(NULL, total_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + TEST_ASSERT_EQ(mem, MAP_FAILED); +} + +static void test_mmap(int fd, size_t total_size) +{ + if (kvm_has_cap(KVM_CAP_GUEST_MEMFD_MAPPABLE)) + test_mmap_allowed(fd, total_size); + else + test_mmap_denied(fd, total_size); } static void test_file_size(int fd, size_t page_size, size_t total_size) @@ -190,7 +233,7 @@ int main(int argc, char *argv[]) fd = vm_create_guest_memfd(vm, total_size, 0); test_file_read_write(fd); - test_mmap(fd, page_size); + test_mmap(fd, total_size); test_file_size(fd, page_size, total_size); test_fallocate(fd, page_size, total_size); test_invalid_punch_hole(fd, page_size, total_size); From patchwork Thu Aug 1 09:01:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13749997 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 5E927C3DA64 for ; Thu, 1 Aug 2024 09:01:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C80B86B009C; Thu, 1 Aug 2024 05:01:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C082F6B009D; Thu, 1 Aug 2024 05:01:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A5B2E6B009E; Thu, 1 Aug 2024 05:01:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 837CD6B009C for ; Thu, 1 Aug 2024 05:01:38 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 3B7F8160960 for ; Thu, 1 Aug 2024 09:01:38 +0000 (UTC) X-FDA: 82403083476.09.37B0B1F Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf24.hostedemail.com (Postfix) with ESMTP id 6DBF218002E for ; Thu, 1 Aug 2024 09:01:36 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=Sj7U9gOR; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf24.hostedemail.com: domain of 3706rZgUKCHYnUVVUaiiafY.Wigfchor-ggepUWe.ila@flex--tabba.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3706rZgUKCHYnUVVUaiiafY.Wigfchor-ggepUWe.ila@flex--tabba.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722502854; a=rsa-sha256; cv=none; b=1clkGozriL281SCB9Qpd8YO+E6zGNUptM61PPGuE9CF2wkqlcy0NNyvwVlPAp61BKPmU75 MBniP4CY/gacJkiXOrlEGX2ZQtaJue3xKbFu1zvXkymuUls4cl5rMhF3Nv2dgcnllznsFW Gjp/dTL6T5gO+wpSz3WOfYBf86a/IpE= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=Sj7U9gOR; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf24.hostedemail.com: domain of 3706rZgUKCHYnUVVUaiiafY.Wigfchor-ggepUWe.ila@flex--tabba.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3706rZgUKCHYnUVVUaiiafY.Wigfchor-ggepUWe.ila@flex--tabba.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722502854; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=eynVCV8vS5USu2ZyXSA4dI0KQ06/f9GaXl4H1mlHW7I=; b=4Hojrf8dDPf0DCD6+piMy7UclAb5MpdTUeoL8mW/MpjKb3xjP1/R/LaS74NEKXOA7Qqau/ 7z1q3sidqaPtdWfMZkSJkmjveVtL1QThBsAPlnWp8le1T5mjeI3EzTB6FE/cULXcKK8aRD eB4FyThARvz7XWN7kQGB0yMNZtQqbyQ= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-64b70c4a269so125586217b3.1 for ; Thu, 01 Aug 2024 02:01:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722502895; x=1723107695; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=eynVCV8vS5USu2ZyXSA4dI0KQ06/f9GaXl4H1mlHW7I=; b=Sj7U9gORJu90+EmEB+udJu5F/lSVfCrFyAlkiRBbEeI6pXHk1SPZlq8SZGvliOENlT VfVUfL6Ung7tjA2Vj0ypeYhH4D5fhM/FouRdBlxhFLOnhn0f6uMRXGVOGgnvZ67fHXiS E8rLsT3J0iBhiq+tmNwHWAxPPSqkLl4O+KikXxSBzSRGVMr/NNQbUDRVkeMurnHYx1u8 d2KqshdFCCP62pnM58KEapecYGibUQox9zdPCYUAfvt0u2dcc3f1HoTlvZ8jZGiNvd91 wGY55FzDHr7OEpDnJetr0Q3SrlQS3VBseeS3IidmJtHXafdhz4SWwNDuJrI5bKZ1mRTz l0Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722502895; x=1723107695; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=eynVCV8vS5USu2ZyXSA4dI0KQ06/f9GaXl4H1mlHW7I=; b=OE4JpT8qZGYq6d2DfkdbVwRMAzTkAjqJDuTKWMBNRa7Zs7RhkYXkQ1VrOkidtbJ0LG ugE9/oLU/0aECN+L6m54FDrsym17WdkoCTP14iTkloO45/cdIyX3poKcw3/c/5UkORo/ f7f5nxucJrZo+VEMEom9Ly8itdfwiOZ5Oe3zXNcL6grXZtTUwBj0kC3GLbxKMNeRDUOY ForDT4zgIxMN6GXhDNE4ax+wXsMgRMueVJuGn1Pob3dcN9WfS4DpZTn3gpgHnMKLV7Md y6EV3LcauG5r8LAn0BcPIMclJyZ29EhQrVsV1UCNOIW/Oy2CM29xlcd/fEVdRctqCYVb pRGg== X-Forwarded-Encrypted: i=1; AJvYcCVwhjzrc/NGG36+wR2z2Ocz9xJum02aStXwpAvdlz6FUE3j0RhF7qepQG5Lf1iSIJy1Sz5RGD0iRU6w+H/Fv4tpdn4= X-Gm-Message-State: AOJu0YwHbqJz7Z15uxnpRM6Vq2ssNTcNcxsCQT1uLWlPssBWGleUe5Dx 4YnrGNM2/UO6blkU4MNAVsMLal90pCwEJZgnuCGklk42GfDFwCMJyf+/8ErC51+ftgjCQ8iuCg= = X-Google-Smtp-Source: AGHT+IGMIr1XUVhclOFb55aW6DOFYObKwVO0wQH5tDUYBTBbgfFm+mNN9/WDhRbYaQh1Bw5e40TmTstGTw== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:a05:6902:2190:b0:e0b:bafe:a7ff with SMTP id 3f1490d57ef6-e0bcd21d5e4mr2642276.6.1722502895329; Thu, 01 Aug 2024 02:01:35 -0700 (PDT) Date: Thu, 1 Aug 2024 10:01:13 +0100 In-Reply-To: <20240801090117.3841080-1-tabba@google.com> Mime-Version: 1.0 References: <20240801090117.3841080-1-tabba@google.com> X-Mailer: git-send-email 2.46.0.rc1.232.g9752f9e123-goog Message-ID: <20240801090117.3841080-7-tabba@google.com> Subject: [RFC PATCH v2 06/10] KVM: arm64: Skip VMA checks for slots without userspace address From: Fuad Tabba To: kvm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-mm@kvack.org Cc: pbonzini@redhat.com, chenhuacai@kernel.org, mpe@ellerman.id.au, anup@brainfault.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, viro@zeniv.linux.org.uk, brauner@kernel.org, willy@infradead.org, akpm@linux-foundation.org, xiaoyao.li@intel.com, yilun.xu@intel.com, chao.p.peng@linux.intel.com, jarkko@kernel.org, amoorthy@google.com, dmatlack@google.com, yu.c.zhang@linux.intel.com, isaku.yamahata@intel.com, mic@digikod.net, vbabka@suse.cz, vannapurve@google.com, ackerleytng@google.com, mail@maciej.szmigiero.name, david@redhat.com, michael.roth@amd.com, wei.w.wang@intel.com, liam.merwick@oracle.com, isaku.yamahata@gmail.com, kirill.shutemov@linux.intel.com, suzuki.poulose@arm.com, steven.price@arm.com, quic_eberman@quicinc.com, quic_mnalajal@quicinc.com, quic_tsoni@quicinc.com, quic_svaddagi@quicinc.com, quic_cvanscha@quicinc.com, quic_pderrin@quicinc.com, quic_pheragu@quicinc.com, catalin.marinas@arm.com, james.morse@arm.com, yuzenghui@huawei.com, oliver.upton@linux.dev, maz@kernel.org, will@kernel.org, qperret@google.com, keirf@google.com, roypat@amazon.co.uk, shuah@kernel.org, hch@infradead.org, jgg@nvidia.com, rientjes@google.com, jhubbard@nvidia.com, fvdl@google.com, hughd@google.com, tabba@google.com X-Rspamd-Queue-Id: 6DBF218002E X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: bsyfba3oi6fgnyfn74uckh7usfcqmagf X-HE-Tag: 1722502896-507450 X-HE-Meta: U2FsdGVkX1/c8yXzBKo8bI7W8kYoXlTMSDr8NCIppx8myDyp9oKxuzxL6s+h57xlXwk4MqAA96UL2Ie0jPrcSlhiBLYZz+Gl4Tb6szx/t0JkFSnf+e+8EnL8/fZ9yEt9ozH1/QvAhcLtf21lpmF5yR/YTSBBKeWPYRSWtOa1skK3aPlijzzRVgEQ84pIuWxMrQ+KfLoC2ERNUERNlKx4zGPHjk5HkRUblIkHGBtZFn3nKxknXQczaeE7uyCBPc79BG6rRqHHLy1BIRvd+em7D61xfrA5CfL6uZ+GZW6pZ33t390TqYK2m4YDOxdJaVNlPTo8+Sp2u+5oht7TEdMlfsHeMzCm2GkHM0qMfMNsBNvGhSpRuje1i7ptHDXlITK3IfYtTrxWCd7VxtrD/5v+7WpdbV4cAptxVCoYgwQv40kZ1P3UEEz8LzLcCmzJyczoEOx1e4yhkox+LE4dfzWHW4Je2ZsU0MLIkxaL+Xbm5L9A/tKidWXmdPYnOpTxm+qGjGHAGKyB96SVFioQTv0FHFCEvBIklsS6jEAO/jfaqLcyxFdol+/joGp6a82EVwjCqE1aozgwjvxrgeWVxhhcvWXh4KFDhfjOADp9LXNdWTsNkTlQFi4F8ILKMk+Z4GhCThHu7R0V7TvObE/uMKM1CMizfxAX2lD6gfGmg4NDdoveF3o/k9Yq7/shsjhjiwR6R+ela395l+vcvR1DfnKRyxykBT1b67wSeU8gqjw0gTb/rympvaytoxu1GWOEEqRw7aXrkfxXd4kDNRAoJMi++i//LyaH2hl9pRtqfpxB7tNg0dJN3yDqQ8uHsihd1s7HqXCtploMoxJChQh+jFMHO2yDoqDPNQ5UI+D4wMaii565AizXedXg2VB8YOGCa24Wh0scW15ME6Rph1SSdI8hhUadWrHJw9kcdcpYJMVBzgKHNGvZnP4mi9lbm1inaDXSTzV9Jacxos3YE/x2Yi0 Brp+frDb ceeqMArnCKjnIf+BpYOHQDpl1PKFKnW6qw40ixU0VG82B03jrzgbkRYd2UyjhsZQl4V5FO39oU+Bipmgh9R2voo9eKcPq5t4tNYbkXD3BTbwZBa30st3xLQeWJhzKe2jU16tLeFY3JJu8EERogtzKQoYHM+Xvp2DJm8qd4mHTmsvR/f9gV9RZmNkh4jB36E0TRQh1WmBpif8A4KG/7CwTIBOcpjI/Z677iAK3Q6YVj35NfLdzneX1IC8hFR4NGe1Qd4XAOagyPCvOQJc/kEbXWHgOTQfWXiQEo7UrFWMUEVrTqgMifusf7hNpaVDSsrE+VnQy9Gkez+EhNPY7+Bsj6DM9UV57RSozkcxJAXijeJZr0iIVWmh8hN9rRvve50DpZ6hB2YeyR6V0yNQ/0ZL48v1cgpKQAjhtvs3Jv7kWTeMPFgvpohZAnxGSqgKN4gd6CkAtK+cU7iOwR68FnaGlYq6ljcz7d0/VZXMbBIzSeKqaJbFL4UyBxI5TIUbymYP75gZuxbfxo+Z7A8oiTbyTCz7pe11hkLZpax0rXyiTAVWbfH4lB8hMs5V6cDAUl8IAdkU9 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000683, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Memory slots backed by guest memory might be created with no intention of being mapped by the host. These are recognized by not having a userspace address in the memory slot. VMA checks are neither possible nor necessary for this kind of slot, so skip them. Signed-off-by: Fuad Tabba --- arch/arm64/kvm/mmu.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 8bcab0cc3fe9..e632e10ea395 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -948,6 +948,10 @@ static void stage2_unmap_memslot(struct kvm *kvm, phys_addr_t size = PAGE_SIZE * memslot->npages; hva_t reg_end = hva + size; + /* Host will not map this private memory without a userspace address. */ + if (kvm_slot_can_be_private(memslot) && !hva) + return; + /* * A memory region could potentially cover multiple VMAs, and any holes * between them, so iterate over all of them to find out if we should @@ -1976,6 +1980,10 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm, hva = new->userspace_addr; reg_end = hva + (new->npages << PAGE_SHIFT); + /* Host will not map this private memory without a userspace address. */ + if ((kvm_slot_can_be_private(new)) && !hva) + return 0; + mmap_read_lock(current->mm); /* * A memory region could potentially cover multiple VMAs, and any holes From patchwork Thu Aug 1 09:01:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13749998 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 B9CE2C3DA4A for ; Thu, 1 Aug 2024 09:01:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 72A576B009E; Thu, 1 Aug 2024 05:01:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6DD2B6B00A0; Thu, 1 Aug 2024 05:01:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 507796B00A1; Thu, 1 Aug 2024 05:01:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 30C176B009E for ; Thu, 1 Aug 2024 05:01:41 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id CCCD9A093E for ; Thu, 1 Aug 2024 09:01:40 +0000 (UTC) X-FDA: 82403083560.25.4506319 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf15.hostedemail.com (Postfix) with ESMTP id D767CA003D for ; Thu, 1 Aug 2024 09:01:38 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=R5ji9+2N; spf=pass (imf15.hostedemail.com: domain of 38U6rZgUKCHgpWXXWckkcha.Ykihejqt-iigrWYg.knc@flex--tabba.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=38U6rZgUKCHgpWXXWckkcha.Ykihejqt-iigrWYg.knc@flex--tabba.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722502870; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=VYgP8TsqpjmhLiOepZBWnEDyKrGoYglq1ochGe+g9ag=; b=JPPYauxjf2UX0Al8FtaSn14FUG2vJ0cuUz9c3Z3XZvCMISBWZZsZTl51NknsT68wL2hFGc b9WgCko5GDE0w+6MIIQ+/exW5VWRWCsSPgnm4VrzZIWvhNWGKxx8AybMFnlkI0rAur6WtR UPJBLGydil+rkxq8wm5BugdfK60aa08= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=R5ji9+2N; spf=pass (imf15.hostedemail.com: domain of 38U6rZgUKCHgpWXXWckkcha.Ykihejqt-iigrWYg.knc@flex--tabba.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=38U6rZgUKCHgpWXXWckkcha.Ykihejqt-iigrWYg.knc@flex--tabba.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722502870; a=rsa-sha256; cv=none; b=KWxQwPOWUzvpSzplkYWcIeUNeWz5uU8UorQs3Cv2sXCHmSbnWAaZfDUVLq8812ttxWJRx+ 44CdSo3XkXc4+ZTGITtOCPbq4C0OeuAZK/ZZh186jiCuqloQGhAYB3kVkP9rSuI/WTjOwn S78dhOHr0m8uFA2SgBJTahYqi8lVuBI= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-65b985bb059so125081087b3.2 for ; Thu, 01 Aug 2024 02:01:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722502898; x=1723107698; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=VYgP8TsqpjmhLiOepZBWnEDyKrGoYglq1ochGe+g9ag=; b=R5ji9+2N4zpRHBHa+rsLWWi8cILA0EOGRUKqsxk9+MMAFOnJwK2UjVwdaumC49edAr tPCaHQl03JUyHWI+MjHVQu5hyTV5PuP/GCGftTOkiBjFAHQOq5g/ZCNYM/wBcaqusT8d /Dbm3U9E2eCi1rfvziZ6uJLy1Bc3Pk1R4JCjhf+dy5XtyOel90aqiagfFVnHuoYEHu/Z Q8A1AptUDx0xP4jSmfHHlMEP8CRkfeyup0oeHFBFbLRu89MaRX7xctN7oK0djY/y6pkx CU85+qWSuJBG+MYc5LOmGlNA0CSsGpoI+ztP7KLP3mxulHEWxSa0x1X0pKBbiUtSwJv8 Rm0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722502898; x=1723107698; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VYgP8TsqpjmhLiOepZBWnEDyKrGoYglq1ochGe+g9ag=; b=lPsY3fugjnQvUqz7f4wnpSNpDtgTTrHdC8bfiCUXp5fjTPwCLLKjbjDUPIm56yCo2p X0EsEd22b9Cs8cSDezJAP1yYn3KfH5gWJMJyH1erW1oUOgLCCg28OkQAv+4jTKZuth9Y 9MT493MWE6aq6Xe/ObFkUl9mXxUJNuSjmZZXQJqDoUbu6PSeiYKm3/nCo7LXr77Axmig 8Sp5kFCk06+rJuTezwLT0ZgdTCfJh1ZtuCtvimQ5y7SvQeReZHRsjvVrJ75g/0IthF4v NoGGX7mWjjIY1n9CeXuy/fn87aASWGMzO+1OyVceScVAI/TJu0M7TNQ0kYha84AafXCu NhTg== X-Forwarded-Encrypted: i=1; AJvYcCUnfjYJiDDYrSTWbj1eWoLtvidnb1bxVB1q/9dxJFhj+TRFMVReDsisCDUjX9956E91cC3qMpgp5qeCc/19155Wg3Y= X-Gm-Message-State: AOJu0YzaLwWK1EGlBRANWYBb4XKL/Xj5dJmbVk9n56IywmF5c58epkS1 pxRJaLms8z3LKKaJ36uNzTjXWIVBGDtZ5HmhYIEsayUGp6lvfblwrJKLbk/NT27qojdr7TxkMA= = X-Google-Smtp-Source: AGHT+IFYiAm/ZMOGWhUa/K3MvrLtTZnEUf3NdBQXNfdF1a3J1k2aDdCJIpsdZ+5mVOdSrR6hCD4FF6rWww== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:a05:6902:1107:b0:e03:6556:9fb5 with SMTP id 3f1490d57ef6-e0bcd3e5b26mr6126276.11.1722502897790; Thu, 01 Aug 2024 02:01:37 -0700 (PDT) Date: Thu, 1 Aug 2024 10:01:14 +0100 In-Reply-To: <20240801090117.3841080-1-tabba@google.com> Mime-Version: 1.0 References: <20240801090117.3841080-1-tabba@google.com> X-Mailer: git-send-email 2.46.0.rc1.232.g9752f9e123-goog Message-ID: <20240801090117.3841080-8-tabba@google.com> Subject: [RFC PATCH v2 07/10] KVM: arm64: Do not allow changes to private memory slots From: Fuad Tabba To: kvm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-mm@kvack.org Cc: pbonzini@redhat.com, chenhuacai@kernel.org, mpe@ellerman.id.au, anup@brainfault.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, viro@zeniv.linux.org.uk, brauner@kernel.org, willy@infradead.org, akpm@linux-foundation.org, xiaoyao.li@intel.com, yilun.xu@intel.com, chao.p.peng@linux.intel.com, jarkko@kernel.org, amoorthy@google.com, dmatlack@google.com, yu.c.zhang@linux.intel.com, isaku.yamahata@intel.com, mic@digikod.net, vbabka@suse.cz, vannapurve@google.com, ackerleytng@google.com, mail@maciej.szmigiero.name, david@redhat.com, michael.roth@amd.com, wei.w.wang@intel.com, liam.merwick@oracle.com, isaku.yamahata@gmail.com, kirill.shutemov@linux.intel.com, suzuki.poulose@arm.com, steven.price@arm.com, quic_eberman@quicinc.com, quic_mnalajal@quicinc.com, quic_tsoni@quicinc.com, quic_svaddagi@quicinc.com, quic_cvanscha@quicinc.com, quic_pderrin@quicinc.com, quic_pheragu@quicinc.com, catalin.marinas@arm.com, james.morse@arm.com, yuzenghui@huawei.com, oliver.upton@linux.dev, maz@kernel.org, will@kernel.org, qperret@google.com, keirf@google.com, roypat@amazon.co.uk, shuah@kernel.org, hch@infradead.org, jgg@nvidia.com, rientjes@google.com, jhubbard@nvidia.com, fvdl@google.com, hughd@google.com, tabba@google.com X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: D767CA003D X-Stat-Signature: canqzdayq8gpdkq58tresx6tfhqye5w4 X-HE-Tag: 1722502898-170398 X-HE-Meta: U2FsdGVkX1+1ZTVvjKo/1xO1PuJ/WzPZsnxrQdwLouqIwQ5qYKokwWB7cHOeiXSpbWj/FhbhmmPTmWrzLeejPL/09QSXh6HGcr+j25DrfWyn8TlQCHDhORafXWVrpLwgujOA3OGWqnl6d8NnRgC1M5XAWoVxTXAmc9FNOI0Mxqvtxg1UaSNolgIW5jkKiJYA/f1NwALCtTyGJ9X22MEMFlGYwOq5qajDSYFB0h7hjAtJkidsr+PLysFu0fDrtm7SaNYy1qlQN2zTAIifGfcw58QEQNzAcIyyJGfSKI4KCDwCd8ctjYcC0exuqQgstRuqxTDkHEg1McTOTUcjF5wOIxmvBViz9C+pcihFvQAOdvDfsQTJe+J9v4gO5l+VLHIDt2ovfScCKRsgtx06Kg8pPEMLIr8O+EvDJRKRl+jtALcrBFZq9uSN6x7zcX+T3cH0xq22cb6dmzqrBI129yohZftrHTMs3UVhVsZopUVcN0sfgzu2mx+s4H+O/ANvY1WYlPC/6bybowCRXrMqMTLAUBLiWJfwXkD1oI25BYaDVqdpWTumJzFtLMvh1xnLNBfTuvJzGvQLHxcItkRWNYnrEb+qySavwBk0VTgbIa1p9jDFfouAaeWMz195jXkijqg1tU+WYuE5c9crohU8+tCBX2Hamu7CCN7iD7zKFyBnGNplBW4l+DDynW5i+0Hn3PlA4WmuUNFncIOIBJSA5eSDyyiSiht0P8kdf42kCVlIyYdyuP8WR3jWeE7rmqLtEOQVYh7YJHHezWBD83475hO+M7DYLK+nOYcg8elYtus+0lqFFDBO2A1fnh0M00ccT+EYxpR5XHa/5auGd2hhtBOGV3UDKF9kfuWuNepPejoImTtSACI9g3BYJ2s1hpv9aOap5jClg0JpP8jaH1N8pSUxsPkauKt0laQV1ep1oxCA++SYL2fsTiOkALbCgrR0CnUKruJFmdkrOX64v0WnFeg wClqDxWY LVEdZgBTN54rgVpdVvj6er2Tv7OrZ1728eL7FJNbTEoTQgnVVbA9PTaqfhnyA/5tk11rR1GN8V12iJMyPKHF2j1c0uaI7/Gy7XqAmAIRuGZr7WeyjYPWTEVP/7mzNLjry8frrsKcPhbeIBUKmDIswe5nQhTzE2plXnUJMS9+3d5k64ZHlVT9MevFPg1znuhgtSTDma7AMWzWnfsWfsPezkoJG9+mNLAFE+UqEfq0ZcalXZzztg5D4kyABDhkNv2acguNMhK4iZPn6QMIW0U2V8dSdR8bg8ih0vpSKGMYTN3gbGbbvBLUurB9t1I4cW4qPQxBk8ovcmiGrqeo7KBOwQa1jeF9NR091v6PR/oAwoGm7nKnK8tz4rvWPVxiXeAyBpTjwSW4LPQ26P6pVmz/JEk0kdEr2UEHu1yuGOxGTe7RJNY5llG6q67jKpx7QwLBObTtjZvY/hSmdOjPRgd4/cVAl+nbAtwOW3PxGmhfF+x0PADisLVyjoZirbWNURckaFzAapgswygrACviuaSQDf5k1whmbQ9mlWWbRjlZmYh9IpebYmMKRRdg/dt4QpTIiRDsJP/sc3F1LDes= X-Bogosity: Ham, tests=bogofilter, spamicity=0.004420, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Handling changes to private memory slots can be difficult, since it would probably require some cooperation from the hypervisor and/or the guest. Do not allow such changes for now. Signed-off-by: Fuad Tabba --- arch/arm64/kvm/mmu.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index e632e10ea395..b1fc636fb670 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1970,6 +1970,10 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm, change != KVM_MR_FLAGS_ONLY) return 0; + if ((change == KVM_MR_MOVE || change == KVM_MR_FLAGS_ONLY) && + ((kvm_slot_can_be_private(old)) || (kvm_slot_can_be_private(new)))) + return -EPERM; + /* * Prevent userspace from creating a memory region outside of the IPA * space addressable by the KVM guest IPA space. From patchwork Thu Aug 1 09:01:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13749999 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 E7224C3DA4A for ; Thu, 1 Aug 2024 09:01:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C80BB6B00A1; Thu, 1 Aug 2024 05:01:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C2F306B00A2; Thu, 1 Aug 2024 05:01:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A85726B00A3; Thu, 1 Aug 2024 05:01:44 -0400 (EDT) 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 84DFF6B00A1 for ; Thu, 1 Aug 2024 05:01:44 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 388F080959 for ; Thu, 1 Aug 2024 09:01:44 +0000 (UTC) X-FDA: 82403083728.05.2416EB2 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf12.hostedemail.com (Postfix) with ESMTP id 51D4F40033 for ; Thu, 1 Aug 2024 09:01:41 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=wbHHEfTG; spf=pass (imf12.hostedemail.com: domain of 39E6rZgUKCHssZaaZfnnfkd.bnlkhmtw-lljuZbj.nqf@flex--tabba.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=39E6rZgUKCHssZaaZfnnfkd.bnlkhmtw-lljuZbj.nqf@flex--tabba.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722502896; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=hPkdSkcYKbc3+kSJZ/g9JVRtvGOqbhaBzYnzj0kRbFw=; b=1PfGx5csB9sqOPzZ0M0D3k4kvXBmiLKAep3JoJP8p0JcP09Zp8PDIIM64L4l2bfyzhbZSr C3vc+UFx0OJYMNHEswZTxmdMeeudRE/5ROrx65ZYKQgsmOHChe8NiP36Q9e6Ts//yWpBa3 KT/ALBvYNaXEbeL840FaN/7AUkzcCGg= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=wbHHEfTG; spf=pass (imf12.hostedemail.com: domain of 39E6rZgUKCHssZaaZfnnfkd.bnlkhmtw-lljuZbj.nqf@flex--tabba.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=39E6rZgUKCHssZaaZfnnfkd.bnlkhmtw-lljuZbj.nqf@flex--tabba.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722502896; a=rsa-sha256; cv=none; b=xZ4Ws+0zNWPqnuria7oXVL4BitmvLDFjJJB/9fLqe4YuKjZPrGOKKK/kEsxhXcEvN1scl+ oQTOz3ryex7/1Y9J+8fzsrFZwTPjLs7tuAj2rcb9XwTOGRYUnJI7k2ZgZP4vmPK/ygAwhv 0Mhvf+DuQ/ROpvFoiOfQJRbPXsMhwOA= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e02a4de4f4eso10350710276.1 for ; Thu, 01 Aug 2024 02:01:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722502900; x=1723107700; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=hPkdSkcYKbc3+kSJZ/g9JVRtvGOqbhaBzYnzj0kRbFw=; b=wbHHEfTGj2ZnvOJrzOOk5GFWx0dE9YpL/bRXvFDoJf4OI6oTVwwRWZG55CuvO2bDCq vDvklKnMxxCcoKdzD3q9q68u6hfIBjADneZiDS/ocImIm67ighDI/ZGKk1wJ1Xgn/NJP VFtt4SD+Jo9Hp8z4jKjHHopuHMAZFzYKn8fV4rPy7rAso+ra9gWMouXG/f5UiTuAJQ/Z OX9UDnrjL/rj9V8Ua1/AURCmQYSWiIMwVx8N404h6AVb0dhogKN7ZlNY6wEXOAvMWsxg ttq9BUVPcvFLhTAdAa0zyH4EJVa8OuSUG/TlfzvUUGb7u9PTBZYbmSvlbLALePHdi4u5 aRfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722502900; x=1723107700; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hPkdSkcYKbc3+kSJZ/g9JVRtvGOqbhaBzYnzj0kRbFw=; b=BFsreYj6oceu1tnrXPI9+vw6ti0jip/pFixapHx73l31NoFINS5aGFJMdGZgOw51q3 O98rbMXCFcWU/QQobnvcNG5yOUk2vnAjYd67l8d1G82N5nlBaAsaWAcFJY70VfcUK7hn 0fT7Y7Vu33oiECR3Gf0UNTAV5Mbkl5eJSNX3HKRnK5VbDYy+9VmvEewluqAq6lm/Cz6I j+c2+lzNyY+Dgr4Gq/rl78iC32Sz79bl5LtRLFtj8pFpFRMHWPxbDwqfiszKDlFBJ3Ue dl1DZvFKSbx5JTiQF0YmKrbzAMZOFOv9T+NKM81SewVxl5w1l2+YtHbSrcNmO8CDcL/7 7oBQ== X-Forwarded-Encrypted: i=1; AJvYcCVFYj+E2/ZnaGX2gwIGx4RV3zIPlFxbb8BgdQ2sblitUPoXkRCPXle5RsKVNynqp187bKgBdROjfUqYm0X/eFjsA0w= X-Gm-Message-State: AOJu0YxH+i/Op8nCZnEbUFy48vV2K0+kdCCzttwJltSOMhf/TUKwyXcL shoNd5Cj1w7O///cX3jEjs2dHpG+ztsdKP6p5n4RIPtmSUPoGPLMPPKp562tQSLITlBPo25oXw= = X-Google-Smtp-Source: AGHT+IFLHM91ijuDJHLUo5+kzuJ4Oi83XUPKih8V/PqPhJPQ78pJ2Ei/0euF1MyM7UCy8SAtSIgxDnFcYw== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:a05:6902:2190:b0:e05:f565:6bd3 with SMTP id 3f1490d57ef6-e0bcd490586mr2277276.12.1722502900177; Thu, 01 Aug 2024 02:01:40 -0700 (PDT) Date: Thu, 1 Aug 2024 10:01:15 +0100 In-Reply-To: <20240801090117.3841080-1-tabba@google.com> Mime-Version: 1.0 References: <20240801090117.3841080-1-tabba@google.com> X-Mailer: git-send-email 2.46.0.rc1.232.g9752f9e123-goog Message-ID: <20240801090117.3841080-9-tabba@google.com> Subject: [RFC PATCH v2 08/10] KVM: arm64: Handle guest_memfd()-backed guest page faults From: Fuad Tabba To: kvm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-mm@kvack.org Cc: pbonzini@redhat.com, chenhuacai@kernel.org, mpe@ellerman.id.au, anup@brainfault.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, viro@zeniv.linux.org.uk, brauner@kernel.org, willy@infradead.org, akpm@linux-foundation.org, xiaoyao.li@intel.com, yilun.xu@intel.com, chao.p.peng@linux.intel.com, jarkko@kernel.org, amoorthy@google.com, dmatlack@google.com, yu.c.zhang@linux.intel.com, isaku.yamahata@intel.com, mic@digikod.net, vbabka@suse.cz, vannapurve@google.com, ackerleytng@google.com, mail@maciej.szmigiero.name, david@redhat.com, michael.roth@amd.com, wei.w.wang@intel.com, liam.merwick@oracle.com, isaku.yamahata@gmail.com, kirill.shutemov@linux.intel.com, suzuki.poulose@arm.com, steven.price@arm.com, quic_eberman@quicinc.com, quic_mnalajal@quicinc.com, quic_tsoni@quicinc.com, quic_svaddagi@quicinc.com, quic_cvanscha@quicinc.com, quic_pderrin@quicinc.com, quic_pheragu@quicinc.com, catalin.marinas@arm.com, james.morse@arm.com, yuzenghui@huawei.com, oliver.upton@linux.dev, maz@kernel.org, will@kernel.org, qperret@google.com, keirf@google.com, roypat@amazon.co.uk, shuah@kernel.org, hch@infradead.org, jgg@nvidia.com, rientjes@google.com, jhubbard@nvidia.com, fvdl@google.com, hughd@google.com, tabba@google.com X-Rspam-User: X-Stat-Signature: 8uxowa8kciywy8aq4tpgnp7bksas8jpy X-Rspamd-Queue-Id: 51D4F40033 X-Rspamd-Server: rspam11 X-HE-Tag: 1722502901-34197 X-HE-Meta: U2FsdGVkX18EC70AkEmcwHgkYJNsoO5MIEkwKBpX5S2HfSgVsVtNf0QvgzbLcNcBetslHB5bm5hw0cS2Rj1lWkBnshw5o8StZhha+yWMp+lP5aE960TGibCuk83BNS9fcSKK22y9Ue7S0BX+LRkjA2wRG5wwq7NagV9R6vHMOOvVQhPPz/YhFWWe6Yb51B6IS8/FX2/i47cR/Oa1Gq60GHeYrVk14JTpj4bptdZrocU/0wRx3LlQ+KlaqLTTzu8SEduhLKWM/WPsp2I1+SzvP1GvOlv/aijItESV6uM8ANrzlTha1H8BSxwVfCZlYcInqSjTH1t3o6mNRagkNUQqRs9z+tiZVPlUmbxF32KIbPK58dv3nvOPUquZjmdXJ98O5/ScP3fYAtjRutvRsFKXG+2Wm1HYGUNt1WS9PEoL82eSf3LyF701nAPAFItQACldUJkPK3pHaflwbhvxN81DWGQ0L3ZX/t1ShMCLKj+nlcVn5difS5YMuuLqEcGFGHdXc2OpjjkmRexbK7tZf08NkCvVYc/3Dz2Jb6+nbTx3/CJnIWAedk5+vI/1ppIIMZt6Z0vjSp9O3FQs5nd2pz0b+uZSHPmrGaIQ8KH3mDLZvs4CS/KmgG1tCv/4svu6yZ9bAPEEba2SF4h/Uo8ktYzvsBvMQ0x5BxadWYHCKGQ07JJqxAKUac9gaty9dHt4aa9SnKnHBlaWmk7g7lXnslrR1FYiLxaDJohaOUuG6p5b8g3Y6ENJbxr3idiGUtL5DkCBxcDjb+452stnx/KltiR4YoimGExhS6Pfk4jWe4AklH8PrrTKpETOK5uOOlIxDcq6tSoQWfzQm9LeXWgBSEcl0sPzdv152ZoH7DigynJYkyJuuYLyoulzovYp4yu0O99s0wq8dFodX2TWzlOCSToYRRPzDAhlq4M1w0ZdQynijlXsRz3UL/VnnRxJnyrvUy4uCpw49C5/y6rtmqQylFS 1sdFQ96z bHfmR4wmnBUAprlWVMBJLyh1ukLXpWfYO25IqV25fRJIl0TLo4qWBTvBOCNob0oPaZ0IfSxLHe7HHQ/ZWug7ic2HfhaQ/n5j/MJ70E8HX5lnIX2QVucNhEnzz0KzhTEcmWCauSdgSxASS64Icl3IE911Hq+52CBwIEz8o+XTkVd++JLFYcwaVtvK7cpnLLf6sG7nMmWzEWraVr7ii4E8TsmMM/XIUzv+mG5yk7nG8Y8vInMlP7I7QSliZOEysB1YYEYJ9exDzzXB1FMUh8VbwroTwKDfbLCGEZ3Eis+eIeTA96CD1RkpD/yd/1iICy+SuH/gPPDP3wuI/9uVZdaP6THvfreCyh5z90JG2Gy9fI16uXz0N+0Nrk4+a1/e6a+EEVSkrcl+UeAvH+m9VFd8rGQIsh2EHscWqLuKNOrs/NxuMHHmBPc55sPZYceJAumKNict+7ZvKTqUsmYXcm80+JgW/NpmGcjkuuAnGLeqT6oJsK6FwN0S96BTrCLoB8w1W3o+bcv0+haaJTYWGB3Bo4zLUMXvdabAlH5QsKJfK5JBc5gCHFs8l5cPKlMhi5U0Dvh6IgXS8VqZ++/p/cYGU10cd03gWbXQIdh7Ktbc6vBijdKjqbC5oWYd77g== 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: Add arm64 support for resolving guest page faults on guest_memfd() backed memslots. This support is not contingent on pKVM, or other confidential computing support, and works in both VHE and nVHE modes. Without confidential computing, this support is useful for testing and debugging. In the future, it might also be useful should a user want to use guest_memfd() for all code, whether it's for a protected guest or not. For now, the fault granule is restricted to PAGE_SIZE. Signed-off-by: Fuad Tabba --- arch/arm64/kvm/mmu.c | 127 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 125 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index b1fc636fb670..e15167865cab 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1378,6 +1378,123 @@ static bool kvm_vma_mte_allowed(struct vm_area_struct *vma) return vma->vm_flags & VM_MTE_ALLOWED; } +static int guest_memfd_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, + struct kvm_memory_slot *memslot, bool fault_is_perm) +{ + struct kvm_mmu_memory_cache *memcache = &vcpu->arch.mmu_page_cache; + bool exec_fault = kvm_vcpu_trap_is_exec_fault(vcpu); + bool logging_active = memslot_is_logging(memslot); + struct kvm_pgtable *pgt = vcpu->arch.hw_mmu->pgt; + enum kvm_pgtable_prot prot = KVM_PGTABLE_PROT_R; + bool write_fault = kvm_is_write_fault(vcpu); + struct mm_struct *mm = current->mm; + gfn_t gfn = gpa_to_gfn(fault_ipa); + struct kvm *kvm = vcpu->kvm; + unsigned long mmu_seq; + struct page *page; + kvm_pfn_t pfn; + int ret; + + /* For now, guest_memfd() only supports PAGE_SIZE granules. */ + if (WARN_ON_ONCE(fault_is_perm && + kvm_vcpu_trap_get_perm_fault_granule(vcpu) != PAGE_SIZE)) { + return -EFAULT; + } + + VM_BUG_ON(write_fault && exec_fault); + + if (fault_is_perm && !write_fault && !exec_fault) { + kvm_err("Unexpected L2 read permission error\n"); + return -EFAULT; + } + + /* + * Permission faults just need to update the existing leaf entry, + * and so normally don't require allocations from the memcache. The + * only exception to this is when dirty logging is enabled at runtime + * and a write fault needs to collapse a block entry into a table. + */ + if (!fault_is_perm || (logging_active && write_fault)) { + ret = kvm_mmu_topup_memory_cache(memcache, + kvm_mmu_cache_min_pages(vcpu->arch.hw_mmu)); + if (ret) + return ret; + } + + /* + * Read mmu_invalidate_seq so that KVM can detect if the results of + * kvm_gmem_get_pfn_locked() become stale prior to acquiring + * kvm->mmu_lock. + */ + mmu_seq = vcpu->kvm->mmu_invalidate_seq; + + /* To pair with the smp_wmb() in kvm_mmu_invalidate_end(). */ + smp_rmb(); + + ret = kvm_gmem_get_pfn_locked(kvm, memslot, gfn, &pfn, NULL); + if (ret) + return ret; + + page = pfn_to_page(pfn); + + if (!kvm_gmem_is_mappable(kvm, gfn, gfn + 1) && + (page_mapped(page) || page_maybe_dma_pinned(page))) { + return -EPERM; + } + + /* + * Once it's faulted in, a guest_memfd() page will stay in memory. + * Therefore, count it as locked. + */ + if (!fault_is_perm) { + ret = account_locked_vm(mm, 1, true); + if (ret) + goto unlock_page; + } + + read_lock(&kvm->mmu_lock); + if (mmu_invalidate_retry(kvm, mmu_seq)) + goto unlock_mmu; + + if (write_fault) + prot |= KVM_PGTABLE_PROT_W; + + if (exec_fault) + prot |= KVM_PGTABLE_PROT_X; + + if (cpus_have_final_cap(ARM64_HAS_CACHE_DIC)) + prot |= KVM_PGTABLE_PROT_X; + + /* + * Under the premise of getting a FSC_PERM fault, we just need to relax + * permissions. + */ + if (fault_is_perm) + ret = kvm_pgtable_stage2_relax_perms(pgt, fault_ipa, prot); + else + ret = kvm_pgtable_stage2_map(pgt, fault_ipa, PAGE_SIZE, + __pfn_to_phys(pfn), prot, + memcache, + KVM_PGTABLE_WALK_HANDLE_FAULT | + KVM_PGTABLE_WALK_SHARED); + + /* Mark the page dirty only if the fault is handled successfully */ + if (write_fault && !ret) { + kvm_set_pfn_dirty(pfn); + mark_page_dirty_in_slot(kvm, memslot, gfn); + } + +unlock_mmu: + read_unlock(&kvm->mmu_lock); + + if (ret && !fault_is_perm) + account_locked_vm(mm, 1, false); +unlock_page: + unlock_page(page); + put_page(page); + return ret != -EAGAIN ? ret : 0; +} + static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, struct kvm_memory_slot *memslot, unsigned long hva, bool fault_is_perm) @@ -1748,8 +1865,14 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu) goto out_unlock; } - ret = user_mem_abort(vcpu, fault_ipa, memslot, hva, - esr_fsc_is_permission_fault(esr)); + if (kvm_slot_can_be_private(memslot)) { + ret = guest_memfd_abort(vcpu, fault_ipa, memslot, + esr_fsc_is_permission_fault(esr)); + } else { + ret = user_mem_abort(vcpu, fault_ipa, memslot, hva, + esr_fsc_is_permission_fault(esr)); + } + if (ret == 0) ret = 1; out: From patchwork Thu Aug 1 09:01:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13750000 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 C4F14C3DA64 for ; Thu, 1 Aug 2024 09:01:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D6BAA6B00A2; Thu, 1 Aug 2024 05:01:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D1BC86B00A3; Thu, 1 Aug 2024 05:01:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BBC2F6B00A4; Thu, 1 Aug 2024 05:01:46 -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 91ED16B00A2 for ; Thu, 1 Aug 2024 05:01:46 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 581ADA6A46 for ; Thu, 1 Aug 2024 09:01:46 +0000 (UTC) X-FDA: 82403083812.27.8B1BB9E Received: from mail-ej1-f74.google.com (mail-ej1-f74.google.com [209.85.218.74]) by imf23.hostedemail.com (Postfix) with ESMTP id 6B596140010 for ; Thu, 1 Aug 2024 09:01:44 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="BO9ZJuC/"; spf=pass (imf23.hostedemail.com: domain of 39k6rZgUKCH0ubccbhpphmf.dpnmjovy-nnlwbdl.psh@flex--tabba.bounces.google.com designates 209.85.218.74 as permitted sender) smtp.mailfrom=39k6rZgUKCH0ubccbhpphmf.dpnmjovy-nnlwbdl.psh@flex--tabba.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722502829; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=zLFB4vtfe+Qz1MMVjY77NoMcItZ1noXdllMM80GyRW8=; b=M93DT9xlhYOnFNFd7T97XE1YaegzlqpjkihEfEmvuRHL2rDwChjJ8hSiOZJBTTNwhHhPTM uOo9wLmQOru6zbu2siexaKrKEzMOyzYqtdNR9vgMkvjT4St5YY3guAY2lprj2n4WteRMHA vMjR2fQJ6S19JcByqijLrmtZpkEOVcI= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="BO9ZJuC/"; spf=pass (imf23.hostedemail.com: domain of 39k6rZgUKCH0ubccbhpphmf.dpnmjovy-nnlwbdl.psh@flex--tabba.bounces.google.com designates 209.85.218.74 as permitted sender) smtp.mailfrom=39k6rZgUKCH0ubccbhpphmf.dpnmjovy-nnlwbdl.psh@flex--tabba.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722502829; a=rsa-sha256; cv=none; b=wdT60Lc3hFJjAKbbqhV+NOCkl6wlpURnaAe0i+0nWFCZHMGUx7J1l305VaGjjrH26tDyL3 9EBScT8j1hFl10MtcPxZtouo5OKB24+Xlzcqw01SMlbmmtO65mBnohmea3U7NAOzN2TArM GgbnXO2AUG5KEaQbFbn9wPwR8H8elyM= Received: by mail-ej1-f74.google.com with SMTP id a640c23a62f3a-a79c35c28f1so592579566b.3 for ; Thu, 01 Aug 2024 02:01:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722502903; x=1723107703; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=zLFB4vtfe+Qz1MMVjY77NoMcItZ1noXdllMM80GyRW8=; b=BO9ZJuC/AckEUUrTgS9HXyA3D2+RAsMavwOqwTeA+QJ8qFMR5SVKb7bcrE0LtdFant KiLMHeIF47awutKAk/mvxLh36oeHNnlj2FT4qDjbVutN5aeXuePmX5JF5wiZlFWMTc1P f9gc8P/AnUQelDqQr3j/8qxURhfgtie0c0Jo3SGsi3Q2iQKPZhIPKwjNEaWM7fSJg8xS 776/BtDa7sUUTE1qPzNw2EQXwb0ShqGEE1t+i8fxULNAItuH8DSap0V9DS6U0pYKmKwo lUR59Ltlp7od5oluB083jR8iJSciRXxDGeQgUrlT4/qZ9+grJBF5AZphAXmnCs9qfolC hfwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722502903; x=1723107703; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zLFB4vtfe+Qz1MMVjY77NoMcItZ1noXdllMM80GyRW8=; b=UX1wm/X5Vv1n8MPoIkW7TGv0Jyd9lA+IU50d6hsa1HWcgi7yimFFhafULNXY5W3yKS v3m5p0LedX7dBnMPl8S1Nzm1sg5Yt4AC2UAKg9GhYLdSRSzzb+c8DqhlLAPeX+8jxRin QCjD9r2WJlRi6nAIzFTk/katIDh/nIZAURlTHwomuOOhuf9AzV25J8UHOXugd3zbzNw2 DppkEfU37O7oZ7u3C8Ghd5wFe1cJ5x/ciYm2LVhNP06mOtLIq3aAyo+V5gcywwsasJij D1VpqlQigJmmSVnFkDYeU26QG3NDvA/aFoKsXeGpsiYb4uEB6NpBcTHFus4XWxcNdNJN 0hfg== X-Forwarded-Encrypted: i=1; AJvYcCV/se5QBqbAQi7L273cFMc8hot3GWg7F5rVoSFvYjUvc6w7Eg6p2AvY73O6B8qGs0pqI2gAZjrDJwKtvQa3G9NO2Qg= X-Gm-Message-State: AOJu0YxGqAXUreAOxyxNTOnOE7CnRGdFPdtEO9tsbEhpFZ5TAF2cB0Xu 5XHBxaUg8tN+nw2vuM55L+wz4sHuLri6iZIVBOe9AIQlhY06zTGfa0XSGQpMEF8atjCdfLmTLQ= = X-Google-Smtp-Source: AGHT+IHTzLe8RYDoIu4Q6eNF/9ig1sSQFAYVxHVp/NRIu780LrDluXUfDxDxS5ts3clkl+0Fh9PskkCJDQ== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:a17:906:3415:b0:a7a:aa12:100a with SMTP id a640c23a62f3a-a7daf11ce02mr180366b.0.1722502902501; Thu, 01 Aug 2024 02:01:42 -0700 (PDT) Date: Thu, 1 Aug 2024 10:01:16 +0100 In-Reply-To: <20240801090117.3841080-1-tabba@google.com> Mime-Version: 1.0 References: <20240801090117.3841080-1-tabba@google.com> X-Mailer: git-send-email 2.46.0.rc1.232.g9752f9e123-goog Message-ID: <20240801090117.3841080-10-tabba@google.com> Subject: [RFC PATCH v2 09/10] KVM: arm64: arm64 has private memory support when config is enabled From: Fuad Tabba To: kvm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-mm@kvack.org Cc: pbonzini@redhat.com, chenhuacai@kernel.org, mpe@ellerman.id.au, anup@brainfault.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, viro@zeniv.linux.org.uk, brauner@kernel.org, willy@infradead.org, akpm@linux-foundation.org, xiaoyao.li@intel.com, yilun.xu@intel.com, chao.p.peng@linux.intel.com, jarkko@kernel.org, amoorthy@google.com, dmatlack@google.com, yu.c.zhang@linux.intel.com, isaku.yamahata@intel.com, mic@digikod.net, vbabka@suse.cz, vannapurve@google.com, ackerleytng@google.com, mail@maciej.szmigiero.name, david@redhat.com, michael.roth@amd.com, wei.w.wang@intel.com, liam.merwick@oracle.com, isaku.yamahata@gmail.com, kirill.shutemov@linux.intel.com, suzuki.poulose@arm.com, steven.price@arm.com, quic_eberman@quicinc.com, quic_mnalajal@quicinc.com, quic_tsoni@quicinc.com, quic_svaddagi@quicinc.com, quic_cvanscha@quicinc.com, quic_pderrin@quicinc.com, quic_pheragu@quicinc.com, catalin.marinas@arm.com, james.morse@arm.com, yuzenghui@huawei.com, oliver.upton@linux.dev, maz@kernel.org, will@kernel.org, qperret@google.com, keirf@google.com, roypat@amazon.co.uk, shuah@kernel.org, hch@infradead.org, jgg@nvidia.com, rientjes@google.com, jhubbard@nvidia.com, fvdl@google.com, hughd@google.com, tabba@google.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 6B596140010 X-Stat-Signature: dn89sqjqphi41xnk4wrw8yakgurtyzgd X-Rspam-User: X-HE-Tag: 1722502904-726481 X-HE-Meta: U2FsdGVkX1+hOSo64BqX2f75PDJVOTlzg22VB7uLIAlqXK//YvRFYm4XgNp75x0FbAGX79RJSHAx8j6Z3KtKw8ii4KRc9e3iTQvgUkk5rRh9bi/Jbn2SDaO1uGCW32Tuty75da62+Vx3OY08c28WL/zkWbAUnGgoc0jwuWQJF7yhiVVUjuI8mDBKZDg8+2sxILiNkRKe/rxyM474Sv34gvET9iixl5fy+/4fcCfj+SB2jy+XEiaivhV904DLpmyitQ47FC7Fva5qfrJaENtmTYppfWygRy41rPFtMcjK7i/rqqIcvQArlOGqK5SvLv7y+9YFiC3CAAJ0nZIXz1+gSPWDkwLwFzz/6eHuxknU2sQ/2SURGtoGucIYLBMwW9jOaHyhkGHrkBB4cnXuFHSycAKa20aAo12gXJOvt3MBFmoDctt6VbPXqyGNveSYAXxAiaMA8HbfE/6UCQDGL49kB+F6Xg5IWGzQzbMVtXmbALWzqGmGzAVrTwR81olf+e9HBkwbYTFRGsaYwtGV8SH7RGo2zsLRY4ZH2YZn8XGdntud3N2A5rA2HImZcFp40Q/79bfaTYvc2abama5Ts879cJvoPIXJ0ENonCgDZjIzyBgQ2NaO3c1W7ShnsYXsb+4Tj7O2p9mQHwnBBbkpCG5JEL15mTRDQk3AoIxxdWBgcRB7tx9ysn/WRxhmsx+l2EDqj6+Last4aZuEsgIeXV7bsciKhqNyxhW9tOi7M4V3IcKk8ikRCX5aq7qdiiYLeb/y7Fs5run5GS55Ey76BNrHgBUheS7CEZuEetNpWg0pj/I32TUFSenBiJot+eEg4j8kbA9Qjo6t2lj36dWJs2oj/UugxoFOLp1hJl0CLG5BSXsvvN6tLfwA4pOLuVmEuq8DoSvHTZCJsW9ZE56sSKuZOGIKIlDv/yGzLapb5p0CmAWV0WnkIWVvOyeH8HhdP6/9TkG4VEExFz4hlYS2f3j 9nMRql+u 0iw1KB+2XZiaE0dXanVoY9GQigfHhA9cyA495hSX/n7E0sbjYU6vp9JtFSvpJ+AkTe3tVG2ELoIkxJNOthJw2hc86YwWpRCmaBCXMwYme1cT8hbf/StnKLix/HIo45LFqLYqmPK8QjKfMl0i8fvHbOXuBLzOSwasHZJl2+RyUENsw7Kt3RhA1YRvNX+cd3e6nIUmpToQvwzZkaWaCKpoMXyyM502uum8Pmv89pSgnEWGAw/LR5SuHmS7lxkcjvnUx+jUEjM2EgLoFu0UGn2y/1T5CRqXlg4lmguOAWyYm5Vm8ngXBFGX7Oi2bVICaW9efXgiVG/UG8GPJGtd7B6TVulVqUsQeo8K81HKF+3TRl0QW7ktRAYvAGmlCRQSrQF3Bc5orn4ED3mSkDXd505B+pJUeN394dRylI1fMI9DD1bJPBO+wIZuW/CCznFsawU9z4oKjSL+fBTRX8WwenLO44d78hBDS+3UBEaGxtcD4HYPn5rQlTvMNoabRPIIUvNZTbM6FCU/HX/OprlK4WtzEcjI/U2fLoC2xGTYGeoGiUxppkUy0uFcZoEv3iwG1Z8vVD95D 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: Implement kvm_arch_has_private_mem() in arm64, making it dependent on the configuration option. Signed-off-by: Fuad Tabba --- arch/arm64/include/asm/kvm_host.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 36b8e97bf49e..8f7d78ee9557 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -1414,4 +1414,7 @@ bool kvm_arm_vcpu_stopped(struct kvm_vcpu *vcpu); (pa + pi + pa3) == 1; \ }) +#define kvm_arch_has_private_mem(kvm) \ + (IS_ENABLED(CONFIG_KVM_PRIVATE_MEM) && is_protected_kvm_enabled()) + #endif /* __ARM64_KVM_HOST_H__ */ From patchwork Thu Aug 1 09:01:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fuad Tabba X-Patchwork-Id: 13750001 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 AF6FEC3DA4A for ; Thu, 1 Aug 2024 09:01:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 701E16B00A3; Thu, 1 Aug 2024 05:01:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6B1156B00A5; Thu, 1 Aug 2024 05:01:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 552A76B00A6; Thu, 1 Aug 2024 05:01:49 -0400 (EDT) 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 2D3B76B00A3 for ; Thu, 1 Aug 2024 05:01:49 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id CFA99A0941 for ; Thu, 1 Aug 2024 09:01:48 +0000 (UTC) X-FDA: 82403083896.05.C6EFF64 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) by imf09.hostedemail.com (Postfix) with ESMTP id D2CD1140043 for ; Thu, 1 Aug 2024 09:01:46 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="H/AGfo4u"; spf=pass (imf09.hostedemail.com: domain of 3-U6rZgUKCIAxeffeksskpi.gsqpmry1-qqozego.svk@flex--tabba.bounces.google.com designates 209.85.128.74 as permitted sender) smtp.mailfrom=3-U6rZgUKCIAxeffeksskpi.gsqpmry1-qqozego.svk@flex--tabba.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722502851; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=8IHbq3nRTqO2jYrZNiv7GHjdo//AKiTG6CX0+AzFu78=; b=q/5ZYB8BPZ5d6eX3hSc+8SUkVh3mAZn+zkvl0TrbrC+SKj9GMwv5atixUQP/cqBlrtSQv2 CJEXLTh+r8WsW1CmD7FLxwD1Gh8bkE1EvWVhZ3tyTCJOK6fdG3kAFTkUuP8mdK/UKF8gaq QvUy5QQyz5byTgiS00JTNyeDi3BNyHE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722502851; a=rsa-sha256; cv=none; b=ZgXnCgHFD3XHjxojEvBYkuS8apyoiE4rRwib+7RLdYcUJ8+B7dVAVgH7UFXSL7jTQTAXHP xlr6YKMwBOLt/wLkMgdCXhCzXQ/yP3SvlIBkD373DgGZO5MC9Ampu14XeQW5N7hucZghm4 AJgVwsJxl3/I9IVnxWEWqdH+TV0f9Zs= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b="H/AGfo4u"; spf=pass (imf09.hostedemail.com: domain of 3-U6rZgUKCIAxeffeksskpi.gsqpmry1-qqozego.svk@flex--tabba.bounces.google.com designates 209.85.128.74 as permitted sender) smtp.mailfrom=3-U6rZgUKCIAxeffeksskpi.gsqpmry1-qqozego.svk@flex--tabba.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-428040f49f9so39730175e9.0 for ; Thu, 01 Aug 2024 02:01:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722502905; x=1723107705; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=8IHbq3nRTqO2jYrZNiv7GHjdo//AKiTG6CX0+AzFu78=; b=H/AGfo4uE3WZaaGoMEzvd3Rya8iJwYii2GMBxwPtJnb2jsqj+mJO3mMJQIV9cPM5Za HjVk4GAG7ev+PXzHuiUzaYyn4uXIGFe6P/O3jg7wd7i+ryvASdXwdfGffMQh9Re7GfQs ABmn9n6PTD8BGc2D/2Rm23ZxWLemZP4iIatpKoOVREoBk/5wAO3UMQZFLWWL8KpxuZkQ +16JBKo1Cq50rg/ytB/WWHxtSABpUYhU7S3LQn7x3O0CEPVoSH+Ay69CuaFiWR+ZXpl5 Mp0iuftCBS2LyDUC5knu3JY21XBcbVkU2+47+R2GmD0p38hAwVK4lOGKHy6Bz8Qv/arq /Hjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722502905; x=1723107705; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8IHbq3nRTqO2jYrZNiv7GHjdo//AKiTG6CX0+AzFu78=; b=gchwNJfLaFktCQHIoismZ4GzHba5b0DvRyw+IrlOWnklN7mNjrApw4RW696V1x8UnZ RXg5ikDj1P7OarCcHgs6kTjAdHUoXyRJsq0mlxqb9FJtRnQ7fyCUwwhQXgEYWaSGX2Nh mV0tOZnIq+3C3UQvETly4tC+dAt2cFOvGjHEwEQKPIg7cgO0yCV63rFzmLK83bxeNVw0 VEUoBGcG+U+nHA/kdAAqFQFN2Ri//rf9SqKL+B5YKBUK5zRA1S+8FCaW91VhB1URqPll cdU/Zz7PRynMUrO0H4JwYJe7E39cH48Qu6Jpuosh0jyOon1NyVw5Pz6NXuFX+QLayeco J86Q== X-Forwarded-Encrypted: i=1; AJvYcCXCuQEKcQwcUmWJMQNhROuNU8B4/AAKW0ldnmI0pZaCCL/untdyunORMcuTm2IxWuhwBKJtIm1xGz4CTmUK6XHcSd0= X-Gm-Message-State: AOJu0Yy1tdKdWtioVon5+xm4YOJjkbbYuzsu0VUNel710Sfp1UWcqVLi /TXFMBoEg5/9TltB/qlAukaI1FRLVxCTalzcZ7blKXLqvE4FUmoS6+mmGWYLkP90btgnnDGLdQ= = X-Google-Smtp-Source: AGHT+IEYAOIgImAvC/AtXq27Mfc53Y7PA+fVTX3Rlx+IY0/mIU2S6P/V0TnGwu9UoSydDFeidGnaFL2tvg== X-Received: from fuad.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1613]) (user=tabba job=sendgmr) by 2002:a5d:4569:0:b0:368:5d2:9e5b with SMTP id ffacd0b85a97d-36baa9ed838mr3368f8f.0.1722502905208; Thu, 01 Aug 2024 02:01:45 -0700 (PDT) Date: Thu, 1 Aug 2024 10:01:17 +0100 In-Reply-To: <20240801090117.3841080-1-tabba@google.com> Mime-Version: 1.0 References: <20240801090117.3841080-1-tabba@google.com> X-Mailer: git-send-email 2.46.0.rc1.232.g9752f9e123-goog Message-ID: <20240801090117.3841080-11-tabba@google.com> Subject: [RFC PATCH v2 10/10] KVM: arm64: Enable private memory kconfig for arm64 From: Fuad Tabba To: kvm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-mm@kvack.org Cc: pbonzini@redhat.com, chenhuacai@kernel.org, mpe@ellerman.id.au, anup@brainfault.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, seanjc@google.com, viro@zeniv.linux.org.uk, brauner@kernel.org, willy@infradead.org, akpm@linux-foundation.org, xiaoyao.li@intel.com, yilun.xu@intel.com, chao.p.peng@linux.intel.com, jarkko@kernel.org, amoorthy@google.com, dmatlack@google.com, yu.c.zhang@linux.intel.com, isaku.yamahata@intel.com, mic@digikod.net, vbabka@suse.cz, vannapurve@google.com, ackerleytng@google.com, mail@maciej.szmigiero.name, david@redhat.com, michael.roth@amd.com, wei.w.wang@intel.com, liam.merwick@oracle.com, isaku.yamahata@gmail.com, kirill.shutemov@linux.intel.com, suzuki.poulose@arm.com, steven.price@arm.com, quic_eberman@quicinc.com, quic_mnalajal@quicinc.com, quic_tsoni@quicinc.com, quic_svaddagi@quicinc.com, quic_cvanscha@quicinc.com, quic_pderrin@quicinc.com, quic_pheragu@quicinc.com, catalin.marinas@arm.com, james.morse@arm.com, yuzenghui@huawei.com, oliver.upton@linux.dev, maz@kernel.org, will@kernel.org, qperret@google.com, keirf@google.com, roypat@amazon.co.uk, shuah@kernel.org, hch@infradead.org, jgg@nvidia.com, rientjes@google.com, jhubbard@nvidia.com, fvdl@google.com, hughd@google.com, tabba@google.com X-Rspamd-Queue-Id: D2CD1140043 X-Stat-Signature: 18gnbz7jiar9h9qjq9qsaira9497cs9a X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1722502906-702053 X-HE-Meta: U2FsdGVkX1/GtdRa8BZdyVyBW0RQpGkPQjwdQaGHpSzZUeGhcpMh5ZCRg2u5hIny2AmbvvxhdQBoxhxdKJN2Kjfqz7RMTo4yHwqNWjcxFCS8eY2cj7RBqIG8zj+BWvom7Q2P7TcgIB7XHTlInhqTDVbi0nz/ZQy7sETcPvXroEIa1kKXuy87HzMvqf3Mu0KhlNWwBNKlYqvMrsI+08dX8GbUsRPAmHoOwY54gSsC7JmQZ7hbOByt/wUJpaccfMUB9uLKd97KeprAne87TbHis5+lmP/eJlWuJcVKUFqnSeXj3DS6TFofD0dfAA5F0EN/5voRB2lXMcdTPlnrUYiusdOeAOK3AvcCaFBi6goi7bJ8UklcnDIGoyVFdFrw+L/HOhuBhaKlErPxBglNnoJY5ZoqR9oUQ3aVLRESCwg1Iv9iExL08qr4fvU0ll38+DtJw6HoOnsi0NN7uMViXUWztI98YNlj9fbriDqSL2fDJvdVKBbNUE5hd/zk7KGpaL6kY4fNV9DGPvuts3RSPn6AN3yFuY6T8nK5O+0XW3sZUW2Xucn67mR38A9JPPBgoXE8gq6DRIS3ySGySO+Ofx2Tz8/Ug6mgGScjcNrhbqY9M6eetg5GkYqAjjHYb5SFddS/fwIeQ8rCMOc8z1Hc2N2CzBm1H87hnhkyDTTr7jd70geeP+zQfs/3OR5bvSoDGY8uyvvLndQJVodEcJWkTAfd1Qhkb/FsCzCNvxth19RT0x6zjozP3H0qO6h0OXi9AFSaqlKSH1daOE1r2zPmHE1q2+z6fvzRNgh7bJ7ClVmZKWARIBLcY/k6Xf2vH+YEC0SYzEcES3bdd67d+lWurPwANS5n1Bslf6fED9woslhVBkTlkgxPQS1iI9hXwlsSf11E6OvMQY6v/7bpO7pMu1NAIfAbsH/h+rXNLzDZDYy3Qswab2tt2tbmqIXqgmtL9tpzFcKsgurdBxqxoOPhrlO LEN7G5wa +5KLp+k0OVpnoysJK/p3egVgiQ1TNq49iUcSyDApuzNqXG5QI30DKgkdiJZ04g/3egcE+16s0pUPsWqBOsX0q0TLZYxB46esgMocx2yfh3HOs0JdTV0E90ACQp5TCh1OreTphW9MTNypJLbo3Bvu3IMrGnSgdhuQ9u2fmwsz1eyH9mLFzqR4V+/2v8Ax3Be9+w+WJ3kboB6CUzp4vLhtLCHzmOn6GkzeUXYpk7QCe04lvG/nSpT1P/dld2ow4RMDL0vi5djVFMVGlWOd0M0Yb3Rnpr31rMHuWOkewIAZeNU88W3eI0kDBFYTiS01rOwP/q8ZnRhsfKGIm+jvdwPAhXyA0gugbK8l9BqKWFjgp89P+pT30YYt/xwWgmUjvleyAdgQEdl8hE8lYSsw3chC7NW9VpiSmfrlaQb0k1GQXaVzfhjcAH1RFsU3f0TlSGWYt2KrlMhqGCvrNn81fKgaT5XA4lNdmCXZbJ9q7hb1sJJTJGYQuw7mA+pYRH/GRHmMf6Du9HF7t4uFQCpxU+0iQ0IRS6xv9Q4j06WadKz3Rpvd3L8WwUq6Yy6cxT6/SUjQ3CCVL X-Bogosity: Ham, tests=bogofilter, spamicity=0.000639, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Now that the infrastructure is in place for arm64 to support guest private memory, enable it in the arm64 kernel configuration. Signed-off-by: Fuad Tabba --- arch/arm64/kvm/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/kvm/Kconfig b/arch/arm64/kvm/Kconfig index 58f09370d17e..8b166c697930 100644 --- a/arch/arm64/kvm/Kconfig +++ b/arch/arm64/kvm/Kconfig @@ -37,6 +37,7 @@ menuconfig KVM select HAVE_KVM_VCPU_RUN_PID_CHANGE select SCHED_INFO select GUEST_PERF_EVENTS if PERF_EVENTS + select KVM_PRIVATE_MEM_MAPPABLE help Support hosting virtualized guest machines.