Message ID | 20230729013535.1070024-7-seanjc@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp904727vqg; Sat, 29 Jul 2023 00:55:30 -0700 (PDT) X-Google-Smtp-Source: APBJJlFZ+jfXh/OHxlwHAjBr0BUkjOwEMzMiSUeAjQ2drENnkJEQFlSPRgfPhUy+rsFo8hUfT6FF X-Received: by 2002:a17:903:1cb:b0:1b8:7483:d488 with SMTP id e11-20020a17090301cb00b001b87483d488mr4604549plh.57.1690617329937; Sat, 29 Jul 2023 00:55:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690617329; cv=none; d=google.com; s=arc-20160816; b=wVM4Bd6rJ7GDgBjRDeXA10dgBLcmtP2K4iO2MsmELGzwdoKh6re4g771pBNiNDJ9hA v4alm+zzpN3NFthVTTa7nMeq76z0tk3qG8ZUjLPeufvbTDBgEzlAdcF+/VkPPQvPdygL QmZ8FtckMhQDUtaTyRXvcsDT808C7j46wFAeLewYJ2tB147MYYm6b3PySqQEBFfLJCe3 YBS4o5yajksABmi7soASbFJ+gxsg+800m0VfEiqH08fNfTt7lXQw5acFWt+wux/1pKB8 nSAgamZw+uZVMT0zR9NSQqv0ZBB4MLe+8jVEN6HtI2cdfx4+AcWzGr9dfGktVKXx+s6/ Hu+g== 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=xRti94I88xI36VdJ1C9pM+DO3reoJ85WhIcKAlj3P2A=; fh=J37Q4aKtoxdyy+p3BpF2uV3z0maXFfn3A5M61jlSlO0=; b=lgjyxSlbrSf7Gbjhg8uW/HhvDSDdI//CrlbvVGJ5Urj4HfwOqkvNtNyX2/taPx7iqq JvujHGYfAfPKV83SpPSjLrlMtYHIYdZhWbDTRJweWyn4X1pjfe36S5/5acoWuoZ19Mz7 LufNvBtCqF4hf+ElQTartWYl7neSBCRGCv4WAiXY+Yyh4ZX2G35N1arO+5lm9J1nnv1k kLUX9gqpbZzwl8EVgzZwvbD/U7aDxzrrP0Fp15Vf7LaD9ZzoBeVuOLAE5VOt7O9+Ws+m PggT4VFQnpeC84VrYP9AEKSsqJw11KKfE4/S0qBiC1WBUqDdlYCTs5e0TjBFv+IondZy QqRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=JzVeSbak; 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 x18-20020a170902ec9200b001b9d090151esi4629619plg.237.2023.07.29.00.55.16; Sat, 29 Jul 2023 00:55:29 -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=JzVeSbak; 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 S237572AbjG2BgM (ORCPT <rfc822;hanasaki@gmail.com> + 99 others); Fri, 28 Jul 2023 21:36:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237535AbjG2BgC (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 28 Jul 2023 21:36:02 -0400 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 304183C28 for <linux-kernel@vger.kernel.org>; Fri, 28 Jul 2023 18:35:56 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id d9443c01a7336-1bbd4f526caso20385265ad.3 for <linux-kernel@vger.kernel.org>; Fri, 28 Jul 2023 18:35:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690594556; x=1691199356; 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=xRti94I88xI36VdJ1C9pM+DO3reoJ85WhIcKAlj3P2A=; b=JzVeSbakvBsITk4WCc6SvXMXZXpKg1sKgNCLCg329z4+CwqicRWa18ItETELkleHut Yv4X8wRd3Le9uqQGPUWs5BUQkj7TQJDt9Eb5fhMjb23YSABFTjI2bzN/glzKpBumIzEs fTGh7mmm0I6apNNmDAUz1eyleS73AlS2QlY8+8eRKCJtqc/P/YOG5SqsNHXCud5EkzFP jE1ZE8Vnryd4Dn0nEp5qJTOVH3Wyqn42CpQxKf2W0v6q+EQhwJBTSDxzWFjjb+QZElus ssNGr64x9a3IHDfdFolrvWOyeULaX7kmUyN6RPwtI37uS4WYyBbIw//m00wT14Fxuhox HQgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690594556; x=1691199356; 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=xRti94I88xI36VdJ1C9pM+DO3reoJ85WhIcKAlj3P2A=; b=YZAADWzKucHEgnB9jJer+RgYJZSK3CBP0OEU+ISDP/CiQlHA3+5o1v+L/cfUzecnG/ 2ABcf6B/JfatJSSGXROmxO34rgPbDPb4tKsRAzMqy9CbJs88G3EdE9UgkOjXOMF3CVrk lFF45hLfh5SGWmDZEt3JEJLUGSRqrxNolPHlRhBv6DDV915fY4Wzt9/WDg1P55kbZ5s0 zc+SY98+7dkBvyzf0YU1dqbO5As+T8/y/N7hHo94yzIztEE2HFS+bok7wTNkMCLFH9Im OSzZZ1c5Chq/FluQ9rnxsvjopxE/NKQOrr3gud6eIOJFmE2dq5FwGDv3SHZ96kGmasX3 WNJA== X-Gm-Message-State: ABy/qLYqvG53IhfBbOVXj33Lm1JAxnQXu1kv1iyJDwmlCNhUDfndY+wC jlShCPIdAjz1Mf/hGdEHMdLzNPjhdAw= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:903:230b:b0:1b9:e338:a8b7 with SMTP id d11-20020a170903230b00b001b9e338a8b7mr13091plh.5.1690594556187; Fri, 28 Jul 2023 18:35:56 -0700 (PDT) Reply-To: Sean Christopherson <seanjc@google.com> Date: Fri, 28 Jul 2023 18:35:12 -0700 In-Reply-To: <20230729013535.1070024-1-seanjc@google.com> Mime-Version: 1.0 References: <20230729013535.1070024-1-seanjc@google.com> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog Message-ID: <20230729013535.1070024-7-seanjc@google.com> Subject: [PATCH v4 06/29] 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>, Yongwei Ma <yongwei.ma@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: INBOX X-GMAIL-THRID: 1772740757500729566 X-GMAIL-MSGID: 1772740757500729566 |
Series |
drm/i915/gvt: KVM: KVMGT fixes and page-track cleanups
|
|
Commit Message
Sean Christopherson
July 29, 2023, 1:35 a.m. UTC
Move the check that a vGPU is attacked from is_2MB_gtt_possible() all the
way up to shadow_ppgtt_mm() to avoid unnecessary work, and to make it more
obvious that a future cleanup of is_2MB_gtt_possible() isn't introducing a
bug.
is_2MB_gtt_possible() has only one caller, ppgtt_populate_shadow_entry(),
and all paths in ppgtt_populate_shadow_entry() eventually check for
attachment by way of intel_gvt_dma_map_guest_page().
And of the paths that lead to ppgtt_populate_shadow_entry(),
shadow_ppgtt_mm() is the only one that doesn't already check for
INTEL_VGPU_STATUS_ACTIVE or INTEL_VGPU_STATUS_ATTACHED.
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]
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 Fri, Jul 28, 2023 at 06:35:12PM -0700, Sean Christopherson wrote: > Move the check that a vGPU is attacked from is_2MB_gtt_possible() all the typo: "attacked" --> "attached" > way up to shadow_ppgtt_mm() to avoid unnecessary work, and to make it more This commit message does not match to what the patch does. The check in the patch is in ppgtt_populate_shadow_entry(). What you want is like below? @@ -1796,6 +1797,9 @@ static int shadow_ppgtt_mm(struct intel_vgpu_mm *mm) if (mm->ppgtt_mm.shadowed) return 0; + if (!test_bit(INTEL_VGPU_STATUS_ATTACHED, vgpu->status)) + return -EINVAL; + mm->ppgtt_mm.shadowed = true; for (index = 0; index < ARRAY_SIZE(mm->ppgtt_mm.guest_pdps); index++) { > obvious that a future cleanup of is_2MB_gtt_possible() isn't introducing a > bug. > > is_2MB_gtt_possible() has only one caller, ppgtt_populate_shadow_entry(), > and all paths in ppgtt_populate_shadow_entry() eventually check for > attachment by way of intel_gvt_dma_map_guest_page(). > > And of the paths that lead to ppgtt_populate_shadow_entry(), > shadow_ppgtt_mm() is the only one that doesn't already check for > INTEL_VGPU_STATUS_ACTIVE or INTEL_VGPU_STATUS_ATTACHED. ... > 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) { > -- > 2.41.0.487.g6d72f3e995-goog >
On Tue, Aug 01, 2023, Yan Zhao wrote: > On Fri, Jul 28, 2023 at 06:35:12PM -0700, Sean Christopherson wrote: > > Move the check that a vGPU is attacked from is_2MB_gtt_possible() all the > typo: "attacked" --> "attached" > > > way up to shadow_ppgtt_mm() to avoid unnecessary work, and to make it more > This commit message does not match to what the patch does. > The check in the patch is in ppgtt_populate_shadow_entry(). > > What you want is like below? Yeah, I completely botched this and forgot to actually change the code. I'll send a replacement patch in-reply (or rather, I already sent it; I missed up again and forgot to hit send on this one earlier in the day...). Thanks yet again for the review!
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) {