Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2753989pxj; Mon, 31 May 2021 09:54:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzESBZr3KlwKAW5IL7n8k2rjD7uF1HuDN859R+EJWDmrzOhlYg5D8bsCNk3Fv9ZoANXnDSA X-Received: by 2002:a05:6402:35d4:: with SMTP id z20mr26380401edc.164.1622480057358; Mon, 31 May 2021 09:54:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622480057; cv=none; d=google.com; s=arc-20160816; b=r/Q/Aw6Q3kYrG5vpqB9NZNCR6CpSMIiIiAS96+e7DDJ0+ydcWgCHcYfHtYN8geARrN GSUtMp0EP9BarVd+Ojm7N+DuB01iGaqEiJoEKtEW/TasGbXu1cYqtbX8e5I/bR8pm/dM InGpyUvxT8nsghWxT6ID0vGjg+SqXCf1k2CTERo5MxIL/sa78Yt4HPijdv4hX43jLweq +0cYSg9xN4skshNSAcdCA2cA4aj5Xf2oTwUmiufewjVlABbZjy36RjYiqZJlDqH69pYi tvLyemyhSH4mSmQE8L19rFgXGnnkOJmJWZm/mdqDiiW5HLXonpyn3uJ+51ZP6Fq2I9Mk LKKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nx63TFOfjDfr1j+f1zWN3J6nyYh1CofFpKQwt47ZBbc=; b=BmYGRP6j3W+FXLfRvRpMMmn9nunZn62uQ9bcpimvTTInGQZhar+0PbdzWYNolweN0E ZAZECrIgoR9EENZ0P/tL9f8/nBpsnILeweJ3CLTi2ooPeYG/QAGVqRKbvCO9EsbvA/pE VRCo2DtNjOEa0KvHLFCuKhJpCRfJPeB8G/DD5IoBd3ip4gaEuWdsGBi7OP0fvSXItZwO mUBNjtBHpjXpxRR9j4fTVv0GamL2GLXfvb+2/uaTPSR2nMkVgW2AIDluRmJ0kW7VXTvf kYiLhnkCw8546FLnquBW1/fwfKBwk0phEAkm3iyNlqRxFDleUotJ3KTPjXHaUfpjRwub W6wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Su9enMj8; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ar9si16730660ejc.663.2021.05.31.09.53.54; Mon, 31 May 2021 09:54:17 -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=@linuxfoundation.org header.s=korg header.b=Su9enMj8; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233742AbhEaQwr (ORCPT + 99 others); Mon, 31 May 2021 12:52:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:51350 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234453AbhEaO7o (ORCPT ); Mon, 31 May 2021 10:59:44 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 321E361413; Mon, 31 May 2021 14:01:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622469701; bh=HIihrXyinQlGhsl/lM+nxWJxwIl1GrGyXLWn1KBymE4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Su9enMj84LaVGT/2Nsr7DcrwVPa9iqj+3NkJtE9ZKFl9MxGraFpxT+WJXR1iiKAuW e/x2NFuOdZojK1SDi8La+T7UZJmA3mkbi3pdiUmUdwgFNwlvcWs4z8lQH3VeVGT+2j zzYuSZyANVz8zroVxKQqohWRT+H42UOosrAqbnQc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vitaly Kuznetsov , Wanpeng Li , Sean Christopherson , Paolo Bonzini , Sasha Levin Subject: [PATCH 5.12 287/296] KVM: X86: hyper-v: Task srcu lock when accessing kvm_memslots() Date: Mon, 31 May 2021 15:15:42 +0200 Message-Id: <20210531130713.363862598@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130703.762129381@linuxfoundation.org> References: <20210531130703.762129381@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wanpeng Li [ Upstream commit da6d63a0062a3ee721b84123b83ec093f25759b0 ] 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 Message-Id: <1621339235-11131-4-git-send-email-wanpengli@tencent.com> Reviewed-by: Sean Christopherson Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin --- 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.30.2