From patchwork Tue Sep 10 23:43:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ackerley Tng X-Patchwork-Id: 13799501 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 9D7D5EE01F2 for ; Tue, 10 Sep 2024 23:46:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 817BF8D00E7; Tue, 10 Sep 2024 19:45:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A1CC8D00E2; Tue, 10 Sep 2024 19:45:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5F4938D00E7; Tue, 10 Sep 2024 19:45:25 -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 36C978D00E2 for ; Tue, 10 Sep 2024 19:45:25 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E59981A0B68 for ; Tue, 10 Sep 2024 23:45:24 +0000 (UTC) X-FDA: 82550462568.02.08F7007 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) by imf03.hostedemail.com (Postfix) with ESMTP id 2F45E2000E for ; Tue, 10 Sep 2024 23:45:22 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=CHU6olBJ; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf03.hostedemail.com: domain of 3EdrgZgsKCIYkmuo1vo83xqqyyqvo.mywvsx47-wwu5kmu.y1q@flex--ackerleytng.bounces.google.com designates 209.85.216.74 as permitted sender) smtp.mailfrom=3EdrgZgsKCIYkmuo1vo83xqqyyqvo.mywvsx47-wwu5kmu.y1q@flex--ackerleytng.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726011847; a=rsa-sha256; cv=none; b=Qgwp+NzWowmBPVxbcAd0Enyj92ZBmcPEftZHwGFN2zhj7MMIquoofy5RhKztmPvFnSD3hH for4xq4Yq2R6SFoaOQiLSutyA3k5jOoXCSHwirRd114/imw4EINxOHBVZhKmUdSWohxFTY bpBXbMi6K+SDuOg/S2sy/I33DGE7+tA= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=CHU6olBJ; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf03.hostedemail.com: domain of 3EdrgZgsKCIYkmuo1vo83xqqyyqvo.mywvsx47-wwu5kmu.y1q@flex--ackerleytng.bounces.google.com designates 209.85.216.74 as permitted sender) smtp.mailfrom=3EdrgZgsKCIYkmuo1vo83xqqyyqvo.mywvsx47-wwu5kmu.y1q@flex--ackerleytng.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1726011847; 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=iSL2kMUQX0MYfWs91FUoGWuk2V9BSwbXfpTOfw5RJmI=; b=iDZFOlAR8BEVJoqn7vP+OdNzW9DVJE9GCXn/qSVH1CZe0xNQqCk3q9W/ezMWZmS9MErFeQ f8+H/28MpqgQGp+dyCQT0xZxcobP3JTR4ZzpoUfwUe+RD9rQo6diireOe2U5Lnu18yFQz2 Qo7ESkBBUxF8pvqGjKjZ2ReJCRhQof8= Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2d87b7618d3so1521718a91.3 for ; Tue, 10 Sep 2024 16:45:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726011922; x=1726616722; 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=iSL2kMUQX0MYfWs91FUoGWuk2V9BSwbXfpTOfw5RJmI=; b=CHU6olBJlFPj2PNaLR18CJxnxVPjgVbd62QsSu3lrSBOBHTaDtxObdTZh9SYDW80Q/ icdzTdmF2mLU7FLz/5d8zgLCBeY0BgXDYdGde/S0DBM3LxzgVUzKI+2Tk6PxzBQT5d5Q hSj9CiQm2Yhk+gK7I+07+UBCWOC5QMQpXWuJaVguERbgqvAWvqDkwuipbGNtIyht/pvM Ls3v8pPrTA11ZAFtzDCvCWE0TCQ6+iYIFZf3PLgtuht5i0JwJ0Q+ZIwYqk6OYKoqsIkE ADIPhaL3DFBx+/XfdcZZ5He7crgpY7S08tQbkXHsIrOZmIgoJe4CL4OJhwR/eTsvGSx1 HL+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726011922; x=1726616722; 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=iSL2kMUQX0MYfWs91FUoGWuk2V9BSwbXfpTOfw5RJmI=; b=lSGQoA2w44AoziWOGLu27bgsG7Pc3vHqDrUDg8uXmuqgH6Ts0PXqMb1VrZ2Pcj1P3I fPUyc1k6ZSljRkjD6dWE+/y0GCP3YHbkCCE0a0VOI4B8lSppoOUFmfT/J1mhhKrw2ejj ZrlfiYIEnV62cBX/GaNpOiIgy8i/5DqBio4Op9z4318IuqWQHY1CjFDfNwaLz+sAalNB g6Q11bRAEFi+bKqbZvvQTntdkkHXVMJ+JHEUsTsWrd8yG5LkYgxRcF9Q6Xz68KvuOM/Y EpF32vHvB9c0aSK0W6GKfkmNeU73+Oh2ZVD+RzDu1Ytzxt/q8N63Y6CjOjS6RjIob16k yetA== X-Forwarded-Encrypted: i=1; AJvYcCVSFQUAns/11/r9sK+nZdOVGA52mLZPAGztkW/X7OgKECHtvEwOpP2CajMYiSO6cM+aQ2uEWu+jTg==@kvack.org X-Gm-Message-State: AOJu0YxglMFr6K3zozQxQwc0+bELzJHZAI68E54rJE9AKTL4OTIL7hbm CpAzvvb6QdmhNqU5MOX1vQE/eVdXAUQbKOYWgZdtCnvp1VGJW5p4GTXM5EUf5Lop8RSMJkJrVON eiFkWiAWhdapY7nhXDge9/w== X-Google-Smtp-Source: AGHT+IHeEJa/t3gbMh3LQ6wjI0/JOXt73EyPzcfCUwf0I0tvYHeE0b/ouOGMNpZEECjGvQ2LqF2A810orFlmLkMS4Q== X-Received: from ackerleytng-ctop.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:13f8]) (user=ackerleytng job=sendgmr) by 2002:a17:90a:c2c5:b0:2d8:bf47:947c with SMTP id 98e67ed59e1d1-2db8304d552mr2449a91.3.1726011921647; Tue, 10 Sep 2024 16:45:21 -0700 (PDT) Date: Tue, 10 Sep 2024 23:43:59 +0000 In-Reply-To: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog Message-ID: Subject: [RFC PATCH 28/39] KVM: guest_memfd: Use vm_type to determine default faultability From: Ackerley Tng To: tabba@google.com, quic_eberman@quicinc.com, roypat@amazon.co.uk, jgg@nvidia.com, peterx@redhat.com, david@redhat.com, rientjes@google.com, fvdl@google.com, jthoughton@google.com, seanjc@google.com, pbonzini@redhat.com, zhiquan1.li@intel.com, fan.du@intel.com, jun.miao@intel.com, isaku.yamahata@intel.com, muchun.song@linux.dev, mike.kravetz@oracle.com Cc: erdemaktas@google.com, vannapurve@google.com, ackerleytng@google.com, qperret@google.com, jhubbard@nvidia.com, willy@infradead.org, shuah@kernel.org, brauner@kernel.org, bfoster@redhat.com, kent.overstreet@linux.dev, pvorel@suse.cz, rppt@kernel.org, richard.weiyang@gmail.com, anup@brainfault.org, haibo1.xu@intel.com, ajones@ventanamicro.com, vkuznets@redhat.com, maciej.wieczor-retman@intel.com, pgonda@google.com, oliver.upton@linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-fsdevel@kvack.org X-Rspamd-Queue-Id: 2F45E2000E X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: jw6ccgbi1gx7qt4yun3ou7ymg5ngytks X-HE-Tag: 1726011922-395605 X-HE-Meta: U2FsdGVkX19fOv08Vt/j7uVplRqpT44nUoiZ1l3XddOcbb76UWdNuLtE/U/PPwAHum96LulHrVsbR327fikCK8GGhwiG0dKSdJtKswUwz444L1XABoub1ZLUe2zv8J4UrP+oSAxgMq0YbnJfWjh3/smf6zLV76KrTD0rbZoImQIm0d2L9jO49BYQ9Nb2HRyHcw5unSV19bTmTFf/YtkV/EA1Fqq4KN4ZlVvBDEgwbJtVMK40NascwIEA4/esXvrnbxYXuhoTFwfifdOcokCkI3ZCOVADGRW7EbmSew2zETgZrPMFYC7WKq35f/IIv5aYDFJF+s8D8hvzhOy8sHlI79QnDyWUR7aoTfKcjW5Y1vDRSmx9ct8wz7NYmaENjMKTci+d0SM64EwYJMoky9JGbyf8WVvMj1mUvTUrzNDLWE5xvRWxwa3np6V/w0tYqaqXsDSk+IkapNfi1lo+PjzD+8o9r5+BzADif1x5yhDXv3CjFA7uAbNE6ejV7CjbauDDsY1GQlLNBELfbduWZ+cgfsYcKyVmUOAmtq1/Yp+3HzrT3TNbKzbmiG/2IkMnoGhhE9mAYzsdd2YbeGYEZhL59ybc5cNAY0s2ORLLy2Cx3j1S1yrEXMHVyA4DYTZMoVJkGim+CudGmrJiR3OwL15ffZLHoPxd8AReCJ+F46ywxVrSoQNKPdI7+GRBBPzOAdD38UFMUZHwUea6fuYl7DiSfKPfW2wmNT7tlCzM3z7e7l2TZV8ziSsXfR4yR5F3rfjX2oesCWD7C2pexvRXqXITN59OzeUHYzPqqAvatqM6G4XP5Q5HnNIH081BwiPwd4PZFJbK12DUU4Gd8rD9M3qCpU0jXxQnacredQlPdeu2IRoWblRzXppsu8G4z9lpfwxvCbxAjFGv40hIsOVzrv0SL76uFUMUtD9mDDGezG6yKf6eKMFurtcK8Y2iQrMymtWxPw46HZwEM/ND9US0zmV v0I5kZS/ Hl2kdYTIu1GOzncotauKUgfey5tYuZcmS2oqrRM0GneY2ZYB8lnwlWx6l3YnpqNg//4HBmPPuqRwswDyXC4PWJhZU/oJg8vjClFHen+jXVomoZNCjNdT+Y32uHLlO7FS1/mLWSx5BSng628ASXKJDA+Z0KVaRufVbBKKpyGvNaruFa5H+fHR59EPlTv5Csg77K8HSRaAxUN2qtkT6TTKUK7No+iRtz7YV/7MEBwW6kOcjAmo1RHWdy+6lg/BQcrTV14CDayLht9CTYXeTJDnxI1ocPyw2zAVQMCy3FxsXIkH7xrWUxkih868aDX7/VxSVYxm+J+aAI77uRDojt7DfEOgc6oY/gTVQnrfkcfi4uDU+t0SHgMiEpI5AjLqZUxq6IZwWbELTaJss4/j3dKldt537qEX4/VKHW1Pq7+weZxEXwVW8W0qwhEmAp0ORsuK3q8xv2gIhJG8n2Kwq/fyFw/tE531GP440ozMEaN+Zv9TUjaJHHnL9A4zy+JYA1/pRxCA0svyJCKRYFOywSIqJmJ+JSVuIeE+ilpoiSAXmtAKHpRb26aDF5RcZYVgJCEX2nzoIUS6a9mHiCrFFs8/QM4+2/1/eNseQFGCtRORgvpvzWGcRdw6fo6McddvUhIXRur/L22s6oAv5JJwJxnFJP65tjVH1GQ6LPP/afXvZImvFz88iaOzTj4PhEnJcUhA4iZz1 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000013, 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 of a KVM_X86_SW_PROTECTED_VM defaults to faultable to align with the default in kvm->mem_attr_array. For this RFC, determine default faultability when associating a range with a memslot. Another option is to determine default faultability at guest_memfd creation time. guest_memfd is created for a specific VM, hence we can set default faultability based on the VM type. In future, if different struct kvms are bound to the same guest_memfd inode, all the struct kvms must be of the same vm_type. TODO: Perhaps faultability should be based on kvm->mem_attr_array? Signed-off-by: Ackerley Tng --- virt/kvm/guest_memfd.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c index fc2483e35876..1d4dfe0660ad 100644 --- a/virt/kvm/guest_memfd.c +++ b/virt/kvm/guest_memfd.c @@ -1256,6 +1256,23 @@ static struct file *kvm_gmem_inode_create_getfile(void *priv, loff_t size, return file; } +static void kvm_gmem_set_default_faultability_by_vm_type(struct inode *inode, + u8 vm_type, + loff_t start, loff_t end) +{ + bool faultable; + + switch (vm_type) { + case KVM_X86_SW_PROTECTED_VM: + faultable = true; + break; + default: + faultable = false; + } + + WARN_ON(kvm_gmem_set_faultable(inode, start, end, faultable)); +} + static int __kvm_gmem_create(struct kvm *kvm, loff_t size, u64 flags) { struct kvm_gmem *gmem; @@ -1378,6 +1395,11 @@ int kvm_gmem_bind(struct kvm *kvm, struct kvm_memory_slot *slot, slot->gmem.pgoff = start; xa_store_range(&gmem->bindings, start, end - 1, slot, GFP_KERNEL); + + kvm_gmem_set_default_faultability_by_vm_type(file_inode(file), + kvm->arch.vm_type, + start, end); + filemap_invalidate_unlock(inode->i_mapping); /*