Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp626093pxb; Wed, 3 Nov 2021 09:39:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwrTfK0JmKLAK+rvpNOFCADP/ujqaBjO8FUSShaEaS6lSZjeapXiFKYiljdWaajYTREikRt X-Received: by 2002:a17:906:7c4:: with SMTP id m4mr56961817ejc.18.1635957550019; Wed, 03 Nov 2021 09:39:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635957550; cv=none; d=google.com; s=arc-20160816; b=waqEpqAk9p9Pp2Lh4kVHZV/WbVS4/XGkxHVJ1sRqDnelT6Tzb9eDzY7Pb+vlTxEGCM JPvIXeD0aTTOjqeJ0F6oZkVgty7L83OCp5IpIG8ZWenPNVA7Mycd2vCelEsDIccbQVEL MT46FIdewK4H9hXwdgfQuW9ucThy+Ni7ybVzjhpmx0DOKOGdO2BNMulJxfzG6hiDiwOW YO3PR5brl5CJrW1S6o2K1qtUyLeTzzSsfo+vC3oXdVGxVh2BCJWSjlXEpeuHOqvMJtvw wuB+1W7zqLBQL5LnzrXIGoALmxSAYCh7qAs6rmj/SPTvTB67KZ928Lsz1r3o2u9MxhZF mRAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=kqcBRxOQ9MjURO/c5n7KjP3zUkTopF6FY6YrmNIOe3I=; b=bYe8fMvhRstEjIBQsv0i8RT096378JeufyF0NhfETOwXhpMIQUWGUNLQeEI2hX+bFe XYZCaap4Zp4NXlYXl21stz94MT96F6ZXWrdMzT4PFxJfEzSgfLSctgPV2wbOOnQcqT1d QMttzi997Og19YZrShNdpzy3sTSvWOdJSSCCt92uXezD48h6BkVZ8GBjIM/s7Q1JtJDS Nw+sNeV4Ngf6w8jVpe8JQO/txLXdAjQeM7RWBKqUTuMqjCTyDQFvaXhqNwJ6/T2kAFRn RQrX3kvNO7jaXHaYICQYHIqlvMqd1wYjRb0TyqfPOjWyuXs6B9zJDc+iEX0UuuK0wIKZ t1+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=cnAmHdOW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gn14si5274580ejc.630.2021.11.03.09.38.44; Wed, 03 Nov 2021 09:39:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=cnAmHdOW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S232890AbhKCQjM (ORCPT + 99 others); Wed, 3 Nov 2021 12:39:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232865AbhKCQjL (ORCPT ); Wed, 3 Nov 2021 12:39:11 -0400 Received: from mail-il1-x12a.google.com (mail-il1-x12a.google.com [IPv6:2607:f8b0:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 145DEC061714 for ; Wed, 3 Nov 2021 09:36:35 -0700 (PDT) Received: by mail-il1-x12a.google.com with SMTP id x9so3166233ilu.6 for ; Wed, 03 Nov 2021 09:36:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=kqcBRxOQ9MjURO/c5n7KjP3zUkTopF6FY6YrmNIOe3I=; b=cnAmHdOWACGRJzcwjbOOl3C9Bd2t/C5gyWAYtrPEglsqE3Y0Cr57sjVPIrLKXctAkE 5ze6sOTjq1x7i85bssik+hzPJ7Di2Sg158ut8fqoiNLcc8lJ0BDU7D0d8FrZPRb4h71+ +a/aWNxxrRtDwjukw9/YQxh4+OJbEErwOu7w3Kpvs1sT2Yi6fk++v010mSvqxNxm9Yce vfJakfaGtwGTZLIpDcwdwOauf3GCmO04s6lMqVtn5f8Gt5PQ34q/dOghZIPPlqdjLW0s UFKyleCoBwJCPJX5ue12uN1atnUM+lga0v2GwHVTwyl2HH6B4FwY18fLwJ3BaeyyIoC4 d9Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=kqcBRxOQ9MjURO/c5n7KjP3zUkTopF6FY6YrmNIOe3I=; b=yAwbTC8HfjIFSjA9Ss04oEBsscw8e+tXlBGvKdzBrVPfn+HWYClmgZdslBgJ2pR82m RvuHKVRDghUGxCrJFzxbnIeSleHlQdCI3hjw7ybB1PBF2kx/qIc8gUnma3mmHXvwMF3l KTzEllEGq8i3tMqGwvwAYP28PLFgt7Cyij3tiGL6kxj+07GrZsOyKrdZ3NbI0mBoyLEL ZV7B+Vc7crIqAxJlrDVA9yfq+L6HP69Iv/mZiaeXUj85KqNZCu1piyCtp2jB78bvgNEv k4HR2VeRWrvAtAiqwXgQUEdxPHxNFvPPjS/mdJmr8x5KTFSF39vQ+X+LuRKWeeogKLx/ P5Gg== X-Gm-Message-State: AOAM531HGNgmkoVFkMFGrEfe9arBHf8Ka7Xr3cxZfuRJkVAa+xwiSk2U 3E3h0s6RgQTmWEPZpIwIx0zitOWG4ZhZkdCLKEsEHg== X-Received: by 2002:a05:6e02:15c9:: with SMTP id q9mr31006491ilu.298.1635957394356; Wed, 03 Nov 2021 09:36:34 -0700 (PDT) MIME-Version: 1.0 References: <20211103161833.3769487-1-seanjc@google.com> In-Reply-To: <20211103161833.3769487-1-seanjc@google.com> From: Ben Gardon Date: Wed, 3 Nov 2021 09:36:23 -0700 Message-ID: Subject: Re: [PATCH] KVM: x86/mmu: Properly dereference rcu-protected TDP MMU sptep iterator To: Sean Christopherson Cc: Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 3, 2021 at 9:18 AM Sean Christopherson wrote: > > Wrap the read of iter->sptep in tdp_mmu_map_handle_target_level() with > rcu_dereference(). Shadow pages in the TDP MMU, and thus their SPTEs, > are protected by rcu. > > This fixes a Sparse warning at tdp_mmu.c:900:51: > warning: incorrect type in argument 1 (different address spaces) > expected unsigned long long [usertype] *sptep > got unsigned long long [noderef] [usertype] __rcu *[usertype] sptep > > Fixes: 7158bee4b475 ("KVM: MMU: pass kvm_mmu_page struct to make_spte") > Cc: Ben Gardon > Signed-off-by: Sean Christopherson Reviewed-by: Ben Gardon This change looks good to me. It also reminds me that the struct kvm_mmu_pages are also protected by RCU. I wonder if it would be worth creating something similar to tdp_ptep_t for the struct kvm_mmu_pages to add RCU annotations to them as well. > --- > arch/x86/kvm/mmu/tdp_mmu.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c > index 7c5dd83e52de..a54c3491af42 100644 > --- a/arch/x86/kvm/mmu/tdp_mmu.c > +++ b/arch/x86/kvm/mmu/tdp_mmu.c > @@ -897,7 +897,7 @@ static int tdp_mmu_map_handle_target_level(struct kvm_vcpu *vcpu, > struct kvm_page_fault *fault, > struct tdp_iter *iter) > { > - struct kvm_mmu_page *sp = sptep_to_sp(iter->sptep); > + struct kvm_mmu_page *sp = sptep_to_sp(rcu_dereference(iter->sptep)); > u64 new_spte; > int ret = RET_PF_FIXED; > bool wrprot = false; > -- > 2.33.1.1089.g2158813163f-goog >