From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4206BC433EF for ; Fri, 18 Feb 2022 11:20:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233482AbiBRLUd (ORCPT ); Fri, 18 Feb 2022 06:20:33 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:46480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231996AbiBRLUb (ORCPT ); Fri, 18 Feb 2022 06:20:31 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5DA4E4348E for ; Fri, 18 Feb 2022 03:20:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1645183214; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cKb0cZODYYb004G8vkUpXzl5M5sjvEaMEp61UfVhGYE=; b=UtjgM1tUJosEHw/U96wCmDS1JVVmZ1H3jaUtHz7XJ+RGTXVRZQ9yHr4jAPrElJh/XldCpC zF9sMJrpg6TDh1KK/1SoGMOB3poITE3507mU6CvaH2C0J+KFoY0LAyEItT3ghetJTB71qn oifdIrxHvauXQ+uCMXyMcEAYbCiX9gI= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-522-3KmgX0t6PiuYJqWVJ1vuqA-1; Fri, 18 Feb 2022 06:20:13 -0500 X-MC-Unique: 3KmgX0t6PiuYJqWVJ1vuqA-1 Received: by mail-ej1-f71.google.com with SMTP id m12-20020a1709062acc00b006cfc98179e2so2919831eje.6 for ; Fri, 18 Feb 2022 03:20:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=cKb0cZODYYb004G8vkUpXzl5M5sjvEaMEp61UfVhGYE=; b=fEdrQ31usoZgQ5w0232m+QZ34Lv+f6S3qQQzQTxwxGb67bNldWxZ5NoCQwJp9EdjAX l3UNqrgPB1YQsojL56msZVPZQxQeJ1azn9rYlrqhOlr3GN4bk14QukNm1Voa6/jpIGTS TLkE7OehAXvC01TX1qB0AtAgVyF0GJK8dewTZieL54K+T2xZRQuYagYXHM1xAB29EsE4 z/Hgxx8xFeK+CNYUgctjzoLTDX8tNJ5Sa7FfD+qjJe9UV3rfXzn2mufKw2wlTvqfGAk2 /A7EvG3yLSSKaefttXEme0+Tg1Ry1073qTC+AGcKfla8K8L+tgYY/eDfAxtWFdJ0SfoF u9Rg== X-Gm-Message-State: AOAM530xXavqh6dAr80P8QnM335VXe2hxkktRqSgGV/HWSjaRfZpAwBP 4SSE8/qyPGZyVr2Wg2ssDFxaIp4wSnNejpfZZdCyYyfQ0QOeAdVJbv3NCtx/WN9Rt4MZv0YMxE2 Tw3mpmWfFIo95Lf8KwPpsTGzQ X-Received: by 2002:a17:906:ae4a:b0:6d0:9eee:e951 with SMTP id lf10-20020a170906ae4a00b006d09eeee951mr1899265ejb.2.1645183211912; Fri, 18 Feb 2022 03:20:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJzopxqIdnzTGCmNYL+f43fQvHudwEnkN8EXmuI9QZ7YMXotpNyJWu9FUG2Za6Ja9QauUua0qA== X-Received: by 2002:a17:906:ae4a:b0:6d0:9eee:e951 with SMTP id lf10-20020a170906ae4a00b006d09eeee951mr1899251ejb.2.1645183211720; Fri, 18 Feb 2022 03:20:11 -0800 (PST) Received: from ?IPV6:2001:b07:6468:f312:c8dd:75d4:99ab:290a? ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.googlemail.com with ESMTPSA id b7sm4403880edv.58.2022.02.18.03.20.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 18 Feb 2022 03:20:11 -0800 (PST) Message-ID: <12b84d17-94cc-6ee7-bde4-340b609c16d2@redhat.com> Date: Fri, 18 Feb 2022 12:20:08 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH 2/2] KVM: x86/pmu: Protect kvm->arch.pmu_event_filter with SRCU Content-Language: en-US To: Like Xu Cc: Sean Christopherson , Eric Hankland , Jim Mattson , Wanpeng Li , Vitaly Kuznetsov , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org References: <20220217083601.24829-1-likexu@tencent.com> <20220217083601.24829-2-likexu@tencent.com> From: Paolo Bonzini In-Reply-To: <20220217083601.24829-2-likexu@tencent.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/17/22 09:36, Like Xu wrote: > From: Like Xu > > Fix the following positive warning: > > ============================= > WARNING: suspicious RCU usage > arch/x86/kvm/pmu.c:190 suspicious rcu_dereference_check() usage! > other info that might help us debug this: > rcu_scheduler_active = 2, debug_locks = 1 > 1 lock held by CPU 28/KVM/370841: > #0: ff11004089f280b8 (&vcpu->mutex){+.+.}-{3:3}, at: kvm_vcpu_ioctl+0x87/0x730 [kvm] > Call Trace: > > dump_stack_lvl+0x59/0x73 > reprogram_fixed_counter+0x15d/0x1a0 [kvm] > kvm_pmu_trigger_event+0x1a3/0x260 [kvm] > ? free_moved_vector+0x1b4/0x1e0 > complete_fast_pio_in+0x8a/0xd0 [kvm] > [...] I think the right fix is to add SRCU protection to complete_userspace_io in kvm_arch_vcpu_ioctl_run. Most calls of complete_userspace_io can execute similar code to vmexits. > Fixes: 66bb8a065f5a ("KVM: x86: PMU Event Filter") It fixes 9cd803d496e7 ("KVM: x86: Update vPMCs when retiring instructions", 2022-01-07), actually. That is when the PMU filter was added to kvm_skip_emulated_instruction (called by kvm_fast_pio_in). Thanks, Paolo > It's possible to call KVM_SET_PMU_EVENT_FILTER ioctl with the vCPU running. > Similar to "kvm->arch.msr_filter", KVM should guarantee that vCPUs will > see either the previous filter or the new filter so that guest pmu events > with identical settings in both the old and new filter have deterministic > behavior.