From patchwork Wed Jul 10 23:42:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Houghton X-Patchwork-Id: 13729873 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0BA85C3DA42 for ; Wed, 10 Jul 2024 23:44:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=jsFdXvbgPwi63ncubEeloKTN1KDlxflVjQmCEhWWdzo=; b=vGM3aEbDUAV0+vMXhdQ/veGdq5 vgLT/980X4yOSlL7gSLe66Zqpsks5ucxyRJeNEkLtdgXHH2ZMv4iXxT+HrLKApwyhYC99VvfkSg/0 EQCiqxL+y7shBDQbpDm09/dIhjv7GEwapHUmJVMc/c1qmgUTlOrTpwSq6fcUTvK971WNE1BEB9bEe p570zwaPurXcfkJHpNvPeKSuyAte9oeD5jW04CfigbHWOQBKRDOyaoTpuDF4DgwAb36Kuuzc06EXZ pGXvIxi89xCJ+OGDiuF1I0npCFNteiMubjChv7ykg5iqdXkOrsdUbgh7b1Ouple1SL68LrYbhAI+L cBYC9fSA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sRgyf-0000000C7s7-4AZg; Wed, 10 Jul 2024 23:44:01 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sRgxO-0000000C78d-1VgH for linux-arm-kernel@lists.infradead.org; Wed, 10 Jul 2024 23:42:44 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-e0561513c21so1392350276.0 for ; Wed, 10 Jul 2024 16:42:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1720654961; x=1721259761; darn=lists.infradead.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=jsFdXvbgPwi63ncubEeloKTN1KDlxflVjQmCEhWWdzo=; b=HInhozWz1XC6v0Rmk2MhpSQet9KbySXnVIiI/Sa8P1gPdI8XEyc3FxSKKGpDZT0cUI ZiTTNS8v5GEzFKzmErPpfUZTz4sK9XKs1FlDz6rsidO5wKvOPH7M5U8OFxXE1yX/OWMh ouAW9GWXQpxt+YR/VlKoZGAoKT/vjPek9ff+ZJP9mcVBnwm9Q6m6RrHxGaYpFp+LX70B 1BeTcO38ysbhrHzGjKRSHpNWbv5AlDxaU/zbCx/OKrnd8A+EzVHPBtgdjZoVBU+al7zi yGvqXQsyQ5Cnbqw0lpOPsWiPsUPU4SwkqpD6yJtugLRu3Jj5dRYD6hBeUlKtZAY8f7++ KOdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720654961; x=1721259761; 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=jsFdXvbgPwi63ncubEeloKTN1KDlxflVjQmCEhWWdzo=; b=TBAzuDrh7MOLPTAhsgRsabwoQJU2K8ohuejya1vbL1C+hI7+im4K+O/MJZTdcfogXQ LEsf1FhHpd6qzE/jV8Fp0JM4A4QN8Hq93sPFF1lm/68FR0ejcgSi9OfjFGQQMuumfZSZ 623bhwbZ8pbX0ghYds/1UymqOMRxS2eJPHbwFRVxd27aky0jV/ZbYV8BPGcZrb0ipb5A G+xvAZ0b5rHq+bTb6cxJxyMnzpSnv4fbgw1+iDREexdoEvjuxxpVMZEluk5cfhCEWgPi 5IQdkapUiA59pFgGx+X5Wqh3w0P3CjdQrJLshvxFtw639Q/dCvLx5geyXLaYOFlw4533 TjIw== X-Forwarded-Encrypted: i=1; AJvYcCXsfuRDsRoC2udB4lRiJ7zdYL/Qy5rk1vQIi/tEdQ5omyMl15XU5DoR5msGHTqFENZ6jNTLFlOfj/UEmG+lSAXveyYZh4tq4y5LlId5cFdWa3h5Kus= X-Gm-Message-State: AOJu0YxbA0YSI62d4HDiTKGCjEMcY+tqqpJM7+fJ+C7hA6xbTJlsloJ8 wJO8jY21DERQlJ7G5kAH+NiFp3NA9JUgcJ39V5b9gbdQbVS26j6asKsFKoIZqDNP/d4L/Ga8dJI /S1NTY/pnS0Ab/iJqJw== X-Google-Smtp-Source: AGHT+IG3Vk6X5wTdtR4KaDZB2edBlrlcDT80/rqBxWjm1e2N+7Y128jb+W0Gi/uqye/vInLab8G3pghPeGswAEHn X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2a4f]) (user=jthoughton job=sendgmr) by 2002:a05:6902:2309:b0:e05:6532:aa4b with SMTP id 3f1490d57ef6-e05780396ccmr53350276.2.1720654960837; Wed, 10 Jul 2024 16:42:40 -0700 (PDT) Date: Wed, 10 Jul 2024 23:42:07 +0000 In-Reply-To: <20240710234222.2333120-1-jthoughton@google.com> Mime-Version: 1.0 References: <20240710234222.2333120-1-jthoughton@google.com> X-Mailer: git-send-email 2.45.2.993.g49e7a77208-goog Message-ID: <20240710234222.2333120-4-jthoughton@google.com> Subject: [RFC PATCH 03/18] KVM: Put struct kvm pointer in memslot From: James Houghton To: Paolo Bonzini Cc: Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Sean Christopherson , Shuah Khan , Peter Xu , Axel Rasmussen , David Matlack , James Houghton , kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240710_164242_470891_8284C5DD X-CRM114-Status: GOOD ( 12.22 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Because a gfn having userfault enabled is tied to a struct kvm, we need a pointer to it. We could pass the kvm pointer around in the routines we need it, but that is a lot of churn, and there isn't much of a downside to simply storing the pointer in the memslot. Signed-off-by: James Houghton --- include/linux/kvm_host.h | 2 ++ virt/kvm/kvm_main.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index f0d4db2d64af..c1eb59a3141b 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -596,6 +596,8 @@ struct kvm_memory_slot { pgoff_t pgoff; } gmem; #endif + + struct kvm *kvm; }; static inline bool kvm_slot_can_be_private(const struct kvm_memory_slot *slot) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index fb7972e61439..ffa452a13672 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1769,6 +1769,7 @@ static void kvm_copy_memslot(struct kvm_memory_slot *dest, dest->flags = src->flags; dest->id = src->id; dest->as_id = src->as_id; + dest->kvm = src->kvm; } static void kvm_invalidate_memslot(struct kvm *kvm, @@ -2078,6 +2079,7 @@ int __kvm_set_memory_region(struct kvm *kvm, new->npages = npages; new->flags = mem->flags; new->userspace_addr = mem->userspace_addr; + new->kvm = kvm; if (mem->flags & KVM_MEM_GUEST_MEMFD) { r = kvm_gmem_bind(kvm, new, mem->guest_memfd, mem->guest_memfd_offset); if (r)