Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2959675pxj; Mon, 17 May 2021 14:09:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtDNKkGI16GPUoi7XYzCYdpJqRgPaEZuk9n/KUDMd3Cy7C+AKWsEqH7CDDNW3Yuk+bo1Tp X-Received: by 2002:a05:6402:510e:: with SMTP id m14mr2406194edd.320.1621285779481; Mon, 17 May 2021 14:09:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621285779; cv=none; d=google.com; s=arc-20160816; b=Hf6IBU3DguhNt9vkztiYlVjk4DOuITRTEsjCEBnP8rCr61Ba5o8/z9XyC6tO0cU4Ww T4T6UEgK3QRDyCmqcJd3RU/fCC6W1Ogbpz2Odf8Ir1thV0OwlsLH+vGnSm5tEAl9bgrw Zy8pX/DHa7wWwQDBOutY7kzwIpiOymz+Dp6vxWI5kLn/Sg/vP5LtCelEcTUWyhNs65t/ m7miCh3asG/F1mGopXjJhuOfaJrw6j7wPWx5u2Rle5GVVI6/6Cjh35DHJLSgsgPpyIVU aEUrTb6ikwT703t7nIhCBDO0d/mE9guDMuXeZsgnnLKhfdHsPWwXAK5agJRekL6tDty4 kZbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=p6jAyFEHVFCxlZGpGxYbrWuXzrXvA1+9+mG4jRlrIQk=; b=T311ELAtctuEPctkAsi2m+fhng4/33pwx0PXzBtpMu3Mjv12k3snGDV249MenZxvV4 PrRKHEERac6b4M5z1mS5Ts+K+JHJh7oRtEBQZAf7P7QYW2p/uJutlljmipfpKpWTvk1P FNrs/VMTBdeIlUNaZDqx6pOyKg0kLVyRhdaafrVbRN0l7/KyflSY1sPn01BhfV+Xk2kd R1namNUBet8Nx84HIkSeOisRLA/gnOkl2jzDQMq2TrofLxZmsYWi65AafvKFOFhcVcFs b8QH+WyOI1mYW4V4YowQhvhLJmSWrqR+Dy9m7JNXV/h3AHZC/MyshiIZokB7Je9LAkiu Li3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hDuAmQ4A; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y11si3654768ejw.103.2021.05.17.14.08.38; Mon, 17 May 2021 14:09:39 -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=@gmail.com header.s=20161025 header.b=hDuAmQ4A; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237636AbhEQOC5 (ORCPT + 99 others); Mon, 17 May 2021 10:02:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237627AbhEQOCs (ORCPT ); Mon, 17 May 2021 10:02:48 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B3CBC061761; Mon, 17 May 2021 07:01:31 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id d78so4141718pfd.10; Mon, 17 May 2021 07:01:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=p6jAyFEHVFCxlZGpGxYbrWuXzrXvA1+9+mG4jRlrIQk=; b=hDuAmQ4A43GWP0rKjcktZ9hykeiArJVyGcpT4ujdQRFXSuywufDCZFAYgkM2exL46R CwYqu8QPpPsZQvgWPTT1EfxUKKA5uEpuCb0xc199tMlwKt67dquZw7yFdxF7BC9Hf06i gROqkq6d/HN1ithnaqgpCkOgwFuUpflhf3GjiQb++cKtJnwnAWVSXDHZGbp+/2abu9m8 pqNeC5PPQNUw6jyeFCDYhqB6ne1SEMGXPztMw/HAbAu6oIxMET7PePOTNzTFrw3yX/Aj 0k7husLzMEEQJ3QCU4/vNMKH3yqX0wgac8QI3+pnAvBC6FNv0GlnPVBbO633fl4WJIcQ t+nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=p6jAyFEHVFCxlZGpGxYbrWuXzrXvA1+9+mG4jRlrIQk=; b=X0h/x0Z+1RxriOTzM8ToK84BYQx67sCePFAj6GYt+VrQmYChpUNr0jFtDHyRIh7fkz 8l/BHWRFVC7M2MU/8Em85RnZmkAQHiHFllBd5yVgTnagCVPeJN50Z4QOiGtWkiDE9UR+ OZn0uy0NgwR70s8LPjP3WuGlPCfiTLFol7pkiCcC62b5SMkTUK+fi23uneOdpP+nCeER D1FKBYSaT/GeWHfpir65PvBiwyEd00jtnVPvMj24dgijcO7TLyuG6BSayWZ1hEkTpoAM AoHgLCfJDq3ezY3kMeBLgz4CFHwAFBVy6hvq8VY0+xTUljWq2TdPdV6hOfwm9zH3PGlr kr9w== X-Gm-Message-State: AOAM532/7L9bUCznphbQnxEFKnIDtXGKirkbJT86ox69ozUITLkDyNFv Upkwq20cfRwOYW153sa0S19Rt8El4yc= X-Received: by 2002:a63:571d:: with SMTP id l29mr9510292pgb.179.1621260090676; Mon, 17 May 2021 07:01:30 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.61]) by smtp.googlemail.com with ESMTPSA id k10sm3074229pfu.175.2021.05.17.07.01.26 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 May 2021 07:01:30 -0700 (PDT) From: Wanpeng Li X-Google-Original-From: Wanpeng Li To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel Subject: [PATCH v3 4/5] KVM: x86: hyper-v: Task srcu lock when accessing kvm_memslots() Date: Mon, 17 May 2021 07:00:27 -0700 Message-Id: <1621260028-6467-4-git-send-email-wanpengli@tencent.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1621260028-6467-1-git-send-email-wanpengli@tencent.com> References: <1621260028-6467-1-git-send-email-wanpengli@tencent.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wanpeng Li WARNING: suspicious RCU usage 5.13.0-rc1 #4 Not tainted ----------------------------- ./include/linux/kvm_host.h:710 suspicious rcu_dereference_check() usage! other info that might help us debug this: rcu_scheduler_active = 2, debug_locks = 1 1 lock held by hyperv_clock/8318: #0: ffffb6b8cb05a7d8 (&hv->hv_lock){+.+.}-{3:3}, at: kvm_hv_invalidate_tsc_page+0x3e/0xa0 [kvm] stack backtrace: CPU: 3 PID: 8318 Comm: hyperv_clock Not tainted 5.13.0-rc1 #4 Call Trace: dump_stack+0x87/0xb7 lockdep_rcu_suspicious+0xce/0xf0 kvm_write_guest_page+0x1c1/0x1d0 [kvm] kvm_write_guest+0x50/0x90 [kvm] kvm_hv_invalidate_tsc_page+0x79/0xa0 [kvm] kvm_gen_update_masterclock+0x1d/0x110 [kvm] kvm_arch_vm_ioctl+0x2a7/0xc50 [kvm] kvm_vm_ioctl+0x123/0x11d0 [kvm] __x64_sys_ioctl+0x3ed/0x9d0 do_syscall_64+0x3d/0x80 entry_SYSCALL_64_after_hwframe+0x44/0xae kvm_memslots() will be called by kvm_write_guest(), so we should take the srcu lock. Fixes: e880c6ea5 (KVM: x86: hyper-v: Prevent using not-yet-updated TSC page by secondary CPUs) Reviewed-by: Vitaly Kuznetsov Signed-off-by: Wanpeng Li --- arch/x86/kvm/hyperv.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c index f98370a39936..f00830e5202f 100644 --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -1172,6 +1172,7 @@ void kvm_hv_invalidate_tsc_page(struct kvm *kvm) { struct kvm_hv *hv = to_kvm_hv(kvm); u64 gfn; + int idx; if (hv->hv_tsc_page_status == HV_TSC_PAGE_BROKEN || hv->hv_tsc_page_status == HV_TSC_PAGE_UNSET || @@ -1190,9 +1191,16 @@ void kvm_hv_invalidate_tsc_page(struct kvm *kvm) gfn = hv->hv_tsc_page >> HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT; hv->tsc_ref.tsc_sequence = 0; + + /* + * Take the srcu lock as memslots will be accessed to check the gfn + * cache generation against the memslots generation. + */ + idx = srcu_read_lock(&kvm->srcu); if (kvm_write_guest(kvm, gfn_to_gpa(gfn), &hv->tsc_ref, sizeof(hv->tsc_ref.tsc_sequence))) hv->hv_tsc_page_status = HV_TSC_PAGE_BROKEN; + srcu_read_unlock(&kvm->srcu, idx); out_unlock: mutex_unlock(&hv->hv_lock); -- 2.25.1