Message ID | 20230513003600.818142-6-seanjc@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp5486351vqo; Fri, 12 May 2023 17:55:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5jHiBmKyKG0KDI+bb8n92oCA6PPwg+MBW+BnzEkmkgbQGlpqh74ua0Yk1sy0DagrXLf6xw X-Received: by 2002:a17:903:230e:b0:1ab:19f6:ef0f with SMTP id d14-20020a170903230e00b001ab19f6ef0fmr37535524plh.33.1683939343995; Fri, 12 May 2023 17:55:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683939343; cv=none; d=google.com; s=arc-20160816; b=sqL9bNN58LZCyBDYjxiGM2KjUU3FiuuPofJNIIQ4zUllaa0y4uONOuJGCzYSRTi9yC WWS+cXVDsP4XzOw74n/dGY6g1lxgjdfyw60JL5N4SEUEmt48sEagxx0EQ0284ROdyo+1 B8Umqp/xF0CqshWNTjVa9JLQNshOiRWyMMsvkIrLXPWEJx0ITAwcVc5d7A30nMWZoTyT DWP+5svAAmS3tbtLimWChBLfuJM0LFp3TstkrDd/pRiJlIjqp3xkDh44llF9JVFtmKw0 fD/CgsVLQVFum6OL88gBHKHl+Xp17fzRNla3UOmdiObEBJAjYtA0Wz8PTnqXIFFi63kJ PACw== 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=bws/OjWeywvM9XkLtSpHOYJ+ALa04I5zAABYQaubhUE=; b=LtRna7PEHiVcVhapNwRDxAOPvj/Y9/r1fWVKLzj5GoChtH5hm9ug9k4/MoNHpTmLYn 2synlCxEZMZyKzalben38PMxKaAuWV6v3iDbV6se6eucXeUs9Y3Q5cULOwJVuijbv1ei Ms2cK+2yc1rVsH7iQQ7d7uMw3cPE+CDsURPe8wBWPWzd4DaBTamDU+mPkeB7YprX1XMB wx0ScRY8QjAUc7WPBp750jyvcYzD6qzSLpQTxFXqj4Lb+Ve1AiUZ07hiU6/Tq+t65Nxv RKEm7xDPeRH7ROU4HiQExpKzmc1F4AYBOFBSFNpcZUjkH6x1pgXF1fPXt4hljxqtzYmh 2G3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=2nK84DtH; 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 hk15-20020a17090b224f00b0025026c97f40si21334528pjb.145.2023.05.12.17.55.29; Fri, 12 May 2023 17:55:43 -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=20221208 header.b=2nK84DtH; 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 S241173AbjEMAg1 (ORCPT <rfc822;peekingduck44@gmail.com> + 99 others); Fri, 12 May 2023 20:36:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241144AbjEMAgW (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 12 May 2023 20:36:22 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BAFD5FCD for <linux-kernel@vger.kernel.org>; Fri, 12 May 2023 17:36:16 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-b8f324b3ef8so13055678276.0 for <linux-kernel@vger.kernel.org>; Fri, 12 May 2023 17:36:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683938175; x=1686530175; 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=bws/OjWeywvM9XkLtSpHOYJ+ALa04I5zAABYQaubhUE=; b=2nK84DtH7omdb7lgN90xeHzmaSrYcT1rO5f/Jmgj+Dv+zaVTUQfWKOjbL4BOhWtkOH CphCTTunIGNQIxuE3yQ2akHe/1RH76qxPs6uXyStOp8VMHUkHauNlfxC5o5QJkgjGNZX VE0x7PQn9vR51EdpRjP3q312V9jMDcwrBozE6gq5to2f2TMIcI2+jGpwh8SVNdO/jT1I Ueje6zg7QEiBe2RJ0mo7uqdWXz+87j9Yl989iyAL5mT032xiSRUFwOyWkjgsZxB9dTjP 7MkO4YuqPEwMFjmSSiu9igcaZ/+IMY85RpkB88NskeeCtT+NtikPvSF5EeCr7kfnC2UF GF1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683938175; x=1686530175; 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=bws/OjWeywvM9XkLtSpHOYJ+ALa04I5zAABYQaubhUE=; b=hqPZwRslNyKOCrkk6NpnrnddkoS1p32y2xV+wHs2s3oiRltX7npfrv8P7FScatBax/ Ab8TX5BHT8LD/9N9NDRl3ES4pocp6wujVWirmg191P1U/R3wtQyjTyTKlImTO8QaOgkI /9KB63YG7Tp3Q2TbX5oJlLYfnwRWkPG6Yh1Be135hJ1uAKfn/r2eU81q4MN8GrL0+3W9 tnkktIJ9yxsP4NLWL06zM3g5CzffgO8IRt1hDWtQlcdE4KcualAgaMYPZJop9iCR7MtA KklQ0EFR6UApDgFt5MKWSVr6op36Ejz2wvKuyyvOqAuiUXRdZz0g25ob7LfxjWoqV5w8 1oPw== X-Gm-Message-State: AC+VfDwspDHVEdGgdROQc9THR9B16TbpW+VyHkgpQXfUUgtHNeTrWOKR Fg32gJBWYed6Xt4JxP7UKhUZ55WxwfM= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:11c9:b0:b9d:ed0f:b9db with SMTP id n9-20020a05690211c900b00b9ded0fb9dbmr16402286ybu.6.1683938175412; Fri, 12 May 2023 17:36:15 -0700 (PDT) Reply-To: Sean Christopherson <seanjc@google.com> Date: Fri, 12 May 2023 17:35:37 -0700 In-Reply-To: <20230513003600.818142-1-seanjc@google.com> Mime-Version: 1.0 References: <20230513003600.818142-1-seanjc@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Message-ID: <20230513003600.818142-6-seanjc@google.com> Subject: [PATCH v3 05/28] drm/i915/gvt: Explicitly check that vGPU is attached before shadowing From: Sean Christopherson <seanjc@google.com> To: Sean Christopherson <seanjc@google.com>, Paolo Bonzini <pbonzini@redhat.com>, Zhenyu Wang <zhenyuw@linux.intel.com>, Zhi Wang <zhi.a.wang@intel.com> Cc: kvm@vger.kernel.org, intel-gvt-dev@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, Yan Zhao <yan.y.zhao@intel.com>, Ben Gardon <bgardon@google.com> Content-Type: text/plain; charset="UTF-8" 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,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765738381491827822?= X-GMAIL-MSGID: =?utf-8?q?1765738381491827822?= |
Series |
drm/i915/gvt: KVM: KVMGT fixes and page-track cleanups
|
|
Commit Message
Sean Christopherson
May 13, 2023, 12:35 a.m. UTC
Move the check that a vGPU is attacked from is_2MB_gtt_possible() to its
sole caller, ppgtt_populate_shadow_entry(). All of the paths in
ppgtt_populate_shadow_entry() eventually check for attachment by way of
intel_gvt_dma_map_guest_page(), but explicitly checking can avoid
unnecessary work and will make it more obvious that a future cleanup of
is_2MB_gtt_possible() isn't introducing a bug.
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
drivers/gpu/drm/i915/gvt/gtt.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
Comments
On 5/13/2023 8:35 AM, Sean Christopherson wrote: > Move the check that a vGPU is attacked from is_2MB_gtt_possible() to its > sole caller, ppgtt_populate_shadow_entry(). All of the paths in > ppgtt_populate_shadow_entry() eventually check for attachment by way of > intel_gvt_dma_map_guest_page(), but explicitly checking can avoid > unnecessary work and will make it more obvious that a future cleanup of > is_2MB_gtt_possible() isn't introducing a bug. > It might be better move this check to shadow_ppgtt_mm() which is used in both shadow page table creation and pinning path so that the path can bail out even earlier when creating a shadow page table but a vGPU has not been attached to KVM yet. > Signed-off-by: Sean Christopherson <seanjc@google.com> > --- > drivers/gpu/drm/i915/gvt/gtt.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/i915/gvt/gtt.c b/drivers/gpu/drm/i915/gvt/gtt.c > index 5426a27c1b71..2aed31b497c9 100644 > --- a/drivers/gpu/drm/i915/gvt/gtt.c > +++ b/drivers/gpu/drm/i915/gvt/gtt.c > @@ -1163,8 +1163,6 @@ static int is_2MB_gtt_possible(struct intel_vgpu *vgpu, > if (!HAS_PAGE_SIZES(vgpu->gvt->gt->i915, I915_GTT_PAGE_SIZE_2M)) > return 0; > > - if (!test_bit(INTEL_VGPU_STATUS_ATTACHED, vgpu->status)) > - return -EINVAL; > pfn = gfn_to_pfn(vgpu->vfio_device.kvm, ops->get_pfn(entry)); > if (is_error_noslot_pfn(pfn)) > return -EINVAL; > @@ -1277,6 +1275,9 @@ static int ppgtt_populate_shadow_entry(struct intel_vgpu *vgpu, > if (!pte_ops->test_present(ge)) > return 0; > > + if (!test_bit(INTEL_VGPU_STATUS_ATTACHED, vgpu->status)) > + return -EINVAL; > + > gfn = pte_ops->get_pfn(ge); > > switch (ge->type) {
On Mon, May 15, 2023, Zhi A Wang wrote: > On 5/13/2023 8:35 AM, Sean Christopherson wrote: > > Move the check that a vGPU is attacked from is_2MB_gtt_possible() to its > > sole caller, ppgtt_populate_shadow_entry(). All of the paths in > > ppgtt_populate_shadow_entry() eventually check for attachment by way of > > intel_gvt_dma_map_guest_page(), but explicitly checking can avoid > > unnecessary work and will make it more obvious that a future cleanup of > > is_2MB_gtt_possible() isn't introducing a bug. > > > > It might be better move this check to shadow_ppgtt_mm() which is used > in both shadow page table creation and pinning path so that the path > can bail out even earlier when creating a shadow page table but a vGPU > has not been attached to KVM yet. Ah, yes, that'll work. I traced through all of the paths that lead to ppgtt_populate_shadow_entry(), and shadow_ppgtt_mm() is the only caller that isn't already gated by INTEL_VGPU_STATUS_ATTACHED or INTEL_VGPU_STATUS_ACTIVE (ACTIVE is set iff ATTACHED is set). I'll move the check up to shadow_ppgtt_mm() in the next version. Thanks! workload_thread() <= pick_next_workload() => INTEL_VGPU_STATUS_ACTIVE | -> dispatch_workload() | |-> prepare_workload() | -> intel_vgpu_sync_oos_pages() | | | |-> ppgtt_set_guest_page_sync() | | | |-> sync_oos_page() | | | |-> ppgtt_populate_shadow_entry() | |-> intel_vgpu_flush_post_shadow() | 1: |-> ppgtt_handle_guest_write_page_table() | |-> ppgtt_handle_guest_entry_add() | 2: | -> ppgtt_populate_spt_by_guest_entry() | | | |-> ppgtt_populate_spt() | | | |-> ppgtt_populate_shadow_entry() | | | |-> ppgtt_populate_spt_by_guest_entry() [see 2] | |-> ppgtt_populate_shadow_entry() kvmgt_page_track_write() <= KVM callback => INTEL_VGPU_STATUS_ATTACHED | |-> intel_vgpu_page_track_handler() | |-> ppgtt_write_protection_handler() | |-> ppgtt_handle_guest_write_page_table_bytes() | |-> ppgtt_handle_guest_write_page_table() [see 1]
diff --git a/drivers/gpu/drm/i915/gvt/gtt.c b/drivers/gpu/drm/i915/gvt/gtt.c index 5426a27c1b71..2aed31b497c9 100644 --- a/drivers/gpu/drm/i915/gvt/gtt.c +++ b/drivers/gpu/drm/i915/gvt/gtt.c @@ -1163,8 +1163,6 @@ static int is_2MB_gtt_possible(struct intel_vgpu *vgpu, if (!HAS_PAGE_SIZES(vgpu->gvt->gt->i915, I915_GTT_PAGE_SIZE_2M)) return 0; - if (!test_bit(INTEL_VGPU_STATUS_ATTACHED, vgpu->status)) - return -EINVAL; pfn = gfn_to_pfn(vgpu->vfio_device.kvm, ops->get_pfn(entry)); if (is_error_noslot_pfn(pfn)) return -EINVAL; @@ -1277,6 +1275,9 @@ static int ppgtt_populate_shadow_entry(struct intel_vgpu *vgpu, if (!pte_ops->test_present(ge)) return 0; + if (!test_bit(INTEL_VGPU_STATUS_ATTACHED, vgpu->status)) + return -EINVAL; + gfn = pte_ops->get_pfn(ge); switch (ge->type) {