From patchwork Thu Oct 13 21:12:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 2378 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp484025wrs; Thu, 13 Oct 2022 14:14:59 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7pYXMdJZ+u1a1CzTekQ6XA9e2zRUt5keAQwi1K88wITvM9vZEOOb/gdUQniMT4PGOcPJWc X-Received: by 2002:a17:903:2cd:b0:182:f36b:31ef with SMTP id s13-20020a17090302cd00b00182f36b31efmr1825009plk.171.1665695699357; Thu, 13 Oct 2022 14:14:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665695699; cv=none; d=google.com; s=arc-20160816; b=N7x4/y1UASAupqsMIAO2wYpmefDPA82ugfwzbXf7r+8YRtoo+nuhLc7bZaJQWw90uf LVWQgkEkXvGxYdvfG+ChKY42Me2mGtTo3r9qz8+Y7AQ7dIN9xUYL4AS3ly8bth11MFP/ t5YuGJ68aAajHprraD4E1YNaSmlDRS1OuDnPSaCUCgEZoO/O8/BnffbQIjy8R9gcqcTi LIRXevXisbVBMTcLU0j5OZxJ4TyUxg2dEtRdOmujLUcjY3MBRShLwufypA3pdBboWbk2 DnDgZ6UCHKj9gXV3ohS9hwlYJWcr45p5Wz742g43P7ZwOoM2oqV/SIlI8aT3glpsDDVg 1NDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=5URKB2UHMUSPpWygEwKHgMdRAkLfFXnLzKwGOMCRDNA=; b=EJIEKBokOamVGLMgqm+OXTnyYTaA7aA2UaWFhyti8tCIa0KAlb1DZFmFer8n45zAzP IrTd4v0x3b/JpheDXBQoy2Bfb9Xc+w/xIzvh08QCwanU/Zh+esR0cydDlBx15VmBNMgm fmSCHbvH4GUfGHWL6kqzUY+aEXHYz9a/4ZPY41Ha9GGkXLMCxkNN16tRZlB1xOPlftpD IyCiTzGKG106jntSFlAoyYiC+64LQM0gv5v/Tq1xyhaiPUck7iJw/4MXkpR3x1aqryKd oldPDnbj/CXsh/LzWHq3Sz4vkm1Ybyx8dX77jBBvb+danOkGG3L062aQ8hAwdYjttCXb yrRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=UKNC2oX0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n126-20020a634084000000b0045ecb2679f1si556165pga.45.2022.10.13.14.14.46; Thu, 13 Oct 2022 14:14:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=UKNC2oX0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230064AbiJMVOE (ORCPT + 99 others); Thu, 13 Oct 2022 17:14:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230146AbiJMVNl (ORCPT ); Thu, 13 Oct 2022 17:13:41 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F2AD192DB7 for ; Thu, 13 Oct 2022 14:13:27 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-3549b9f0a03so28040567b3.11 for ; Thu, 13 Oct 2022 14:13:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=5URKB2UHMUSPpWygEwKHgMdRAkLfFXnLzKwGOMCRDNA=; b=UKNC2oX08Dn5jOmQaFh8md74layXZhPEWoVtlgyMroHsnDPxL9Ea4oOE99qmFZKq35 c/rLwzP18IC/7p/JVrfDeh8kN2cowwAN6IbStXMfiY3r5he7mlWqzRYwplCfiCsVKlFR beyqEUJa6kiF+TycHjvtt5ttKot4XXozvmzS53XK4tISWavxxqJxecXn+FH51b0th1rd 4uRhaeMV8UAV3LShApu0XEjCuUUNQ+agDoal03x65LKmf5LXR7Zk67B+Qu5NJkMIfZrn 6W3aUB5e0ujvuP1lNjRimNix4mKv2pZ4WBlWNv3IEGmMpb3LiiFoptN5NXk8Ojsx6fzm uYRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=5URKB2UHMUSPpWygEwKHgMdRAkLfFXnLzKwGOMCRDNA=; b=LCLnCryZiz78sJCJLE8Ufq3cYa+MSzT8lVX6rRVqb6YEt2/0DckB1DKjl1Xh8f0vc9 nfpKK1Xob2okp1xSeMzowTso/wla2/fYweQKl1x0IyTgY+ikVPNoCFlLqW18B0PokVW1 fpezJIGh9kgZvwjcoyfxVIFXyEIqLtO+PVtLC0KXn5tRHcQUqMBfg3lxb5Zm/EhRCWJc wSKAsF/GX/H0DN3cG/35O4fnqKCOioRDtc3J3G/QfXGYZ0kKa+R0wNNfiF/xC1O7yF0D cNMgMAsZvygL/+ZJWSm4j+YnYnILm4XXur9lMZGDsbI48QLTykP25T5/m8j5s1aEY4j3 cDqg== X-Gm-Message-State: ACrzQf1N9DTwedh1iHsEctqbHxC2FsbdKgGaKpLkoJfesCCOrOug/Jtc NdeRAEkl5tBCi5KgqBc1HU+paIrzOTM= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:3746:0:b0:6bd:33bc:a284 with SMTP id e67-20020a253746000000b006bd33bca284mr1714965yba.506.1665695572592; Thu, 13 Oct 2022 14:12:52 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 13 Oct 2022 21:12:26 +0000 In-Reply-To: <20221013211234.1318131-1-seanjc@google.com> Mime-Version: 1.0 References: <20221013211234.1318131-1-seanjc@google.com> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog Message-ID: <20221013211234.1318131-9-seanjc@google.com> Subject: [PATCH v2 08/16] KVM: Use gfn_to_pfn_cache's immutable "kvm" in kvm_gpc_check() From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Michal Luczaj , David Woodhouse X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746608533527837585?= X-GMAIL-MSGID: =?utf-8?q?1746608533527837585?= From: Michal Luczaj Make kvm_gpc_check() use kvm instance cached in gfn_to_pfn_cache. Suggested-by: Sean Christopherson Signed-off-by: Michal Luczaj Signed-off-by: Sean Christopherson --- arch/x86/kvm/x86.c | 2 +- arch/x86/kvm/xen.c | 12 ++++++------ include/linux/kvm_host.h | 3 +-- virt/kvm/pfncache.c | 4 ++-- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 0b4fa3455f3a..b357a84f8c49 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3033,7 +3033,7 @@ static void kvm_setup_guest_pvclock(struct kvm_vcpu *v, WARN_ON_ONCE(gpc->len != offset + sizeof(*guest_hv_clock)); read_lock_irqsave(&gpc->lock, flags); - while (!kvm_gpc_check(v->kvm, gpc, gpc->gpa)) { + while (!kvm_gpc_check(gpc, gpc->gpa)) { read_unlock_irqrestore(&gpc->lock, flags); if (kvm_gpc_refresh(v->kvm, gpc, gpc->gpa)) diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c index 6f5a5507392e..c7304f37c438 100644 --- a/arch/x86/kvm/xen.c +++ b/arch/x86/kvm/xen.c @@ -211,7 +211,7 @@ void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, int state) return; read_lock_irqsave(&gpc->lock, flags); - while (!kvm_gpc_check(v->kvm, gpc, gpc->gpa)) { + while (!kvm_gpc_check(gpc, gpc->gpa)) { read_unlock_irqrestore(&gpc->lock, flags); /* When invoked from kvm_sched_out() we cannot sleep */ @@ -344,7 +344,7 @@ void kvm_xen_inject_pending_events(struct kvm_vcpu *v) * little more honest about it. */ read_lock_irqsave(&gpc->lock, flags); - while (!kvm_gpc_check(v->kvm, gpc, gpc->gpa)) { + while (!kvm_gpc_check(gpc, gpc->gpa)) { read_unlock_irqrestore(&gpc->lock, flags); if (kvm_gpc_refresh(v->kvm, gpc, gpc->gpa)) @@ -407,7 +407,7 @@ int __kvm_xen_has_interrupt(struct kvm_vcpu *v) sizeof_field(struct compat_vcpu_info, evtchn_upcall_pending)); read_lock_irqsave(&gpc->lock, flags); - while (!kvm_gpc_check(v->kvm, gpc, gpc->gpa)) { + while (!kvm_gpc_check(gpc, gpc->gpa)) { read_unlock_irqrestore(&gpc->lock, flags); /* @@ -947,7 +947,7 @@ static bool wait_pending_event(struct kvm_vcpu *vcpu, int nr_ports, read_lock_irqsave(&gpc->lock, flags); idx = srcu_read_lock(&kvm->srcu); - if (!kvm_gpc_check(kvm, gpc, gpc->gpa)) + if (!kvm_gpc_check(gpc, gpc->gpa)) goto out_rcu; ret = false; @@ -1338,7 +1338,7 @@ int kvm_xen_set_evtchn_fast(struct kvm_xen_evtchn *xe, struct kvm *kvm) idx = srcu_read_lock(&kvm->srcu); read_lock_irqsave(&gpc->lock, flags); - if (!kvm_gpc_check(kvm, gpc, gpc->gpa)) + if (!kvm_gpc_check(gpc, gpc->gpa)) goto out_rcu; if (IS_ENABLED(CONFIG_64BIT) && kvm->arch.xen.long_mode) { @@ -1372,7 +1372,7 @@ int kvm_xen_set_evtchn_fast(struct kvm_xen_evtchn *xe, struct kvm *kvm) gpc = &vcpu->arch.xen.vcpu_info_cache; read_lock_irqsave(&gpc->lock, flags); - if (!kvm_gpc_check(kvm, gpc, gpc->gpa)) { + if (!kvm_gpc_check(gpc, gpc->gpa)) { /* * Could not access the vcpu_info. Set the bit in-kernel * and prod the vCPU to deliver it for itself. diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index c79f2e122ac8..ad8ef7f2d705 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1282,7 +1282,6 @@ int kvm_gpc_activate(struct gfn_to_pfn_cache *gpc, gpa_t gpa); /** * kvm_gpc_check - check validity of a gfn_to_pfn_cache. * - * @kvm: pointer to kvm instance. * @gpc: struct gfn_to_pfn_cache object. * @gpa: current guest physical address to map. * @@ -1296,7 +1295,7 @@ int kvm_gpc_activate(struct gfn_to_pfn_cache *gpc, gpa_t gpa); * Callers in IN_GUEST_MODE may do so without locking, although they should * still hold a read lock on kvm->scru for the memslot checks. */ -bool kvm_gpc_check(struct kvm *kvm, struct gfn_to_pfn_cache *gpc, gpa_t gpa); +bool kvm_gpc_check(struct gfn_to_pfn_cache *gpc, gpa_t gpa); /** * kvm_gpc_refresh - update a previously initialized cache. diff --git a/virt/kvm/pfncache.c b/virt/kvm/pfncache.c index 34883ad12536..6fe76fb4d228 100644 --- a/virt/kvm/pfncache.c +++ b/virt/kvm/pfncache.c @@ -76,9 +76,9 @@ void gfn_to_pfn_cache_invalidate_start(struct kvm *kvm, unsigned long start, } } -bool kvm_gpc_check(struct kvm *kvm, struct gfn_to_pfn_cache *gpc, gpa_t gpa) +bool kvm_gpc_check(struct gfn_to_pfn_cache *gpc, gpa_t gpa) { - struct kvm_memslots *slots = kvm_memslots(kvm); + struct kvm_memslots *slots = kvm_memslots(gpc->kvm); if (!gpc->active) return false;