From patchwork Thu Oct 13 21:12:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 2380 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp484101wrs; Thu, 13 Oct 2022 14:15:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4w9WVRrR1wpknBfy/07KFkMw+G0Pqf2lCAmqNOR5AnSm+WnbBnuBKUinBk8oaqaAZQrOPY X-Received: by 2002:a63:5a1b:0:b0:461:9934:6f62 with SMTP id o27-20020a635a1b000000b0046199346f62mr1623343pgb.266.1665695713569; Thu, 13 Oct 2022 14:15:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665695713; cv=none; d=google.com; s=arc-20160816; b=FupeWx5nVBwA06GPgGhr3zp5fLOnLtePbV7BcgVDCpcsEe8OuDTAfPAFXZMhWywERZ 1DrskW6JDKJQjZ76TTQPQ62C2vP+UCdmol4S+tvNXemxG3IWvGlsg9L8xjxq1n0513mx 1M4ysJHgt65qQQ13d0MZt0Jzzu8LK4jSCVypNs/fFZvq/RZvV6nhrE506DnMBMWnuNGc z9uPRqY4k6Md4YDRW9K7l8vmSyZ23b9K6oyweUmiXS7+W+/KF4m3T7EspD4EoXWNSVE3 qK6yz6JHyQGola82VlFpdAwOxHOqhHXiV88ZFsJPxkYqsCl2USMJDi4HcFcTXaF6GtHA 9mlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date:reply-to :dkim-signature; bh=E0wMVancUSCdQHm6xrhPLp8XHQC+Zfx0f39Z7/tw4F8=; b=1CU1BdOI9oob8YRJwx02AVZY/IpMDU4yDetzb+Cma5ZdYsRh+kHxuW3LqoXZegm4+f 10GEq/iYVDS8BN4IzQTBJFLgpgHOxWOhcxFzH561gGa5+AnvyNkMVrzDTFB9bLFFWdE3 Hjij7HgDgHO34rLdwbRr0gLzv5ghcUe5NKLMFdsvKKxqhVWqrRlMWzgScOPualjhYb4G C20/pw2va8h7Y7cfqOH1DKPwrgNvLxeJwXeM1xPbZ+GCtai7PQhTJuQQ8xSTSjRiHThh +If/9E9R3fJ1zkLN63aaxPr5x97K1DPkax/l7oKFEfVS0fP/2u6/c+lWgu0J6Zn5u74n LiJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=FFpkcBRB; 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 t41-20020a056a0013a900b0053abdfb0228si529308pfg.338.2022.10.13.14.15.01; Thu, 13 Oct 2022 14:15:13 -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=FFpkcBRB; 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 S230173AbiJMVOU (ORCPT + 99 others); Thu, 13 Oct 2022 17:14:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230157AbiJMVNm (ORCPT ); Thu, 13 Oct 2022 17:13:42 -0400 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0BC2019374F for ; Thu, 13 Oct 2022 14:13:30 -0700 (PDT) Received: by mail-pf1-x449.google.com with SMTP id q18-20020aa79832000000b00562d921e30aso1784665pfl.4 for ; Thu, 13 Oct 2022 14:13:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=content-transfer-encoding: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=E0wMVancUSCdQHm6xrhPLp8XHQC+Zfx0f39Z7/tw4F8=; b=FFpkcBRBwqGjxj/2Lpmkxa6nmJHRfRTkJpW/HdkN5dV56vwsisFFcKuCEj+zyvPIUN zbsnmso3/Zhfw4UCU8XmMyJxpZ+75WFMFFMg3MVqWCfm9cz3CYhKkTuFdXwfc70R8P2c 2G1pnZFZmEpjNtMUldatsG0ALoHLtyh/xAd+i21jg8831ZyzvmLJld6tXHYg2Y1JmpPx RGR5YvjLX1ls8cG4ssSHfCxAPHC4iP6VRfVBrag3kWoH01c25sR59X0HfzCQqopGO5+j xvtnNaJhpA0E10sdWhUupebK+0P7ROqzAelJQhQG+eB38BRxvC6z5LwkHJmvFEyH+ab1 AG7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding: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=E0wMVancUSCdQHm6xrhPLp8XHQC+Zfx0f39Z7/tw4F8=; b=wv/Xd+n6gkeKd4MMHLvn3duMTqFziie0fnFDFvKB8lePwfoAw51Srf/4aBhMYFK+mc 1nH2wclGbN7PzZdukid55JhYC9e9g63IyNZvh+OgibX7X46e5Mzkhy69Xg+E5wMM/A96 P4hziDiCi1VH4pFBsk6KKD9+BBhJWxBFujo0NJf+KqZOXch5r+qF0hSbIioJ7grspVDl ANp2o2oVpf3si5eNjkuigCPkW+tPr5aHTOl+Fc0uMl1vmyNymkiK4IlwIi2o7FunZBY7 y8BAQaCdJtHUZSJ9dfCjeSwGtz4msCY8GA6XJq77KO6oAep/hhdMpXmh9jJDldtXKrxV +f1w== X-Gm-Message-State: ACrzQf17N1Ukr4l1jdOo081Poc4TGM5jII7NXlVmPKybNmWIY8359CDw FjU4YMt4tHQtSjwQdHaGr9f/3pzCTc0= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:868b:b0:185:be8:b316 with SMTP id g11-20020a170902868b00b001850be8b316mr1578925plo.157.1665695573969; Thu, 13 Oct 2022 14:12:53 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 13 Oct 2022 21:12:27 +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-10-seanjc@google.com> Subject: [PATCH v2 09/16] KVM: Clean up hva_to_pfn_retry() 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?1746608548562859596?= X-GMAIL-MSGID: =?utf-8?q?1746608548562859596?= From: Michal Luczaj Make hva_to_pfn_retry() use kvm instance cached in gfn_to_pfn_cache. Suggested-by: Sean Christopherson Signed-off-by: Michal Luczaj Signed-off-by: Sean Christopherson --- virt/kvm/pfncache.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/virt/kvm/pfncache.c b/virt/kvm/pfncache.c index 6fe76fb4d228..ef7ac1666847 100644 --- a/virt/kvm/pfncache.c +++ b/virt/kvm/pfncache.c @@ -138,7 +138,7 @@ static inline bool mmu_notifier_retry_cache(struct kvm *kvm, unsigned long mmu_s return kvm->mmu_invalidate_seq != mmu_seq; } -static kvm_pfn_t hva_to_pfn_retry(struct kvm *kvm, struct gfn_to_pfn_cache *gpc) +static kvm_pfn_t hva_to_pfn_retry(struct gfn_to_pfn_cache *gpc) { /* Note, the new page offset may be different than the old! */ void *old_khva = gpc->khva - offset_in_page(gpc->khva); @@ -158,7 +158,7 @@ static kvm_pfn_t hva_to_pfn_retry(struct kvm *kvm, struct gfn_to_pfn_cache *gpc) gpc->valid = false; do { - mmu_seq = kvm->mmu_invalidate_seq; + mmu_seq = gpc->kvm->mmu_invalidate_seq; smp_rmb(); write_unlock_irq(&gpc->lock); @@ -216,7 +216,7 @@ static kvm_pfn_t hva_to_pfn_retry(struct kvm *kvm, struct gfn_to_pfn_cache *gpc) * attempting to refresh. */ WARN_ON_ONCE(gpc->valid); - } while (mmu_notifier_retry_cache(kvm, mmu_seq)); + } while (mmu_notifier_retry_cache(gpc->kvm, mmu_seq)); gpc->valid = true; gpc->pfn = new_pfn; @@ -293,7 +293,7 @@ int kvm_gpc_refresh(struct kvm *kvm, struct gfn_to_pfn_cache *gpc, gpa_t gpa) * drop the lock and do the HVA to PFN lookup again. */ if (!gpc->valid || old_uhva != gpc->uhva) { - ret = hva_to_pfn_retry(kvm, gpc); + ret = hva_to_pfn_retry(gpc); } else { /* If the HVA→PFN mapping was already valid, don't unmap it. */ old_pfn = KVM_PFN_ERR_FAULT;