Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp223677rwd; Wed, 24 May 2023 17:11:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Y9zgGegmhqHBw/Zb7IPpTovHFALzpEB42fuBo4UG7QXPFb/XTbfnvBafhvOd9Gexm25oO X-Received: by 2002:a05:6a00:1a93:b0:647:1cb7:b714 with SMTP id e19-20020a056a001a9300b006471cb7b714mr5956979pfv.3.1684973464222; Wed, 24 May 2023 17:11:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684973464; cv=none; d=google.com; s=arc-20160816; b=J0zJYfPzyOcrytYVKF6wdVVyXUup9dlXOCZuFqiL8+sk9B7etwqopS+r6oSCvTTOeB aF0btGDBkkCGvVt1pioroXiqS0+BtZ6JY0Fuew9JE270WTwGkW7pez0uO8ruZJr2vB4b dzhnjxLtc5CSatDgUSk1e2GRGYbDcG+v9r/0w8n5mipOvUoYypO0h7h7yTtxjhFf3/mu A92TiSO28b05EQXXG2pyUmPEdjLGFfUxH+yOzVRhHdmnGItg0ssSh57V5Y8K6MJ6Zk9B MlZgVfhW3YvaVyoPIivi7TnJNlwogeRQutm3srHstclOF/mHdC30PIIgM8pF+z/u8P8p QgCQ== 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:dkim-signature; bh=cSR7SiejqAADkjtE2sfBUw7kBDCwXi6R0Pqg2+hbZ5M=; b=T1JdzPCxAH62pE1DJKVbjgGjb+u9Tm03RULY25Eaxzm3kfen7Uj38+s/3Q2NQA3ob3 IGhcjm2PFqIAoqM40BUycNC1RZQnqny3k45XE+nl5r0i2ksancReIVljVERSbPvvCpGS hqs19XfEsuZxVlAn8TwcyDqTODxf8yBK1VRxwV5QHPXBF/evd+yO/g6aglcK7RKl3kS9 kiB+i6g6iJ47T9yOoH7bd45r1mTaRuKCHd/l/zdcqCQabkAtiN4bjwpjJzdj2Xy42Ylf GJcDezgUxdKjl/UQjqq8MIRWD1YQ1JzD3x6DbEleKcjLdZllRiTWuqBQ4GfZerckYnee MKkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b="sBgm/c/e"; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t15-20020a63954f000000b0050bfa82c243si552646pgn.17.2023.05.24.17.10.39; Wed, 24 May 2023 17:11:04 -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="sBgm/c/e"; 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 S229650AbjEXXu7 (ORCPT + 99 others); Wed, 24 May 2023 19:50:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229612AbjEXXu6 (ORCPT ); Wed, 24 May 2023 19:50:58 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03E9C99 for ; Wed, 24 May 2023 16:50:57 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id d2e1a72fcca58-64d2d0f5132so907155b3a.3 for ; Wed, 24 May 2023 16:50:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684972256; x=1687564256; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=cSR7SiejqAADkjtE2sfBUw7kBDCwXi6R0Pqg2+hbZ5M=; b=sBgm/c/eypRScnM/5VK84NQJotHmdUBdtdu7k+AA2ntAYB6j5QG/rkORL1OXol+KHR V8olrWLcq19w9iPuiX8It70T0bWgLUavXKJVcMFrc9Lcc5uNtTL3TSMcBs6peyxVYbHz 8TJwNaRveyodUpGx9k1rKBmJBq6fJYXXo3pftEa2308DCGiNODq5j7xEaVXVbBilzMZR nUvrsvFQxCd4Jh1hWPgKLPYY84wfc/rszy2CSOGTQIirnhWYC64OIaDAYkPGm4obhw+Q KvfboAFt7XMNOhnDUGg7wdUu6I1fkWo6S+YncB0LvSAtW8ZcIyBYPPGeODVGBwdqcnBI 4/vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684972256; x=1687564256; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cSR7SiejqAADkjtE2sfBUw7kBDCwXi6R0Pqg2+hbZ5M=; b=cx7sJcaG4pk19odC8Zojl16xGhmJ0BGrrePdkkLFcpl+twfh4OGPqeg8NfDj2hAWyY 2hLKQ3kfzjeCk783HWqoCXsRpkms7kTcaDpXKtfaerZKq6KDSkxGJiXPaPmGEtc9Kd9U cX2UzxLbTh6aDqo0UUi/epEh+Wcycjp6/IsBS5vUBAlGy9JYNjU21F4hHaMsSe/5d38y qgtN7qQeMUbBxQVcCOKSYsIYg4pBF0jvM3sS+XrIbRee/jjqW44iXoo1zLuuyjslsIUH AoF2xSswDT7t1FIJNWQE1ky8ha+jLqUls7wEewU5GEUwT2nlCSPJkuyc97zAl5JwKuYb JI5Q== X-Gm-Message-State: AC+VfDxO4G0Vs+t4MqaJpzvWaiXbqVsV08V7DRLCtbZqUMRFS0Cxo+2w IHFqI5f9KZrZERHdor8D8RyIpcxRzMU= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:189c:b0:63a:ff2a:bf9f with SMTP id x28-20020a056a00189c00b0063aff2abf9fmr1730016pfh.2.1684972256482; Wed, 24 May 2023 16:50:56 -0700 (PDT) Date: Wed, 24 May 2023 16:50:54 -0700 In-Reply-To: <20230420104622.12504-8-ljrcore@126.com> Mime-Version: 1.0 References: <20230420104622.12504-1-ljrcore@126.com> <20230420104622.12504-8-ljrcore@126.com> Message-ID: Subject: Re: [PATCH v2 7/7] KVM: selftests: Test pmu event filter with incompatible kvm_pmu_event_filter From: Sean Christopherson To: Jinrong Liang Cc: Like Xu , Paolo Bonzini , Jonathan Corbet , Shuah Khan , Aaron Lewis , David Matlack , Vishal Annapurve , Wanpeng Li , Bagas Sanjaya , Jinrong Liang , linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="us-ascii" 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: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 20, 2023, Jinrong Liang wrote: > From: Jinrong Liang > > From: Jinrong Liang > > Add test to verify the behavior of the pmu event filter when an > incomplete kvm_pmu_event_filter structure is used. By running the > test, we can ensure that the pmu event filter correctly handles > incomplete structures and does not allow events to be counted when > they should not be. > > Signed-off-by: Jinrong Liang > --- > .../kvm/x86_64/pmu_event_filter_test.c | 23 +++++++++++++++++++ > 1 file changed, 23 insertions(+) > > diff --git a/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c b/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c > index 9be4c6f8fb7e..a6b6e0d086ae 100644 > --- a/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c > +++ b/tools/testing/selftests/kvm/x86_64/pmu_event_filter_test.c > @@ -881,6 +881,24 @@ static bool fixed_ctr_is_allowed(uint8_t idx, uint32_t action, uint32_t bitmap) > (action == KVM_PMU_EVENT_DENY && !(bitmap & BIT_ULL(idx))); > } > > +struct incompatible_pmu_event_filter { > + __u32 action; > + __u32 nevents; > + __u32 fixed_counter_bitmap; > +}; > + > +static uint64_t test_incompatible_filter(struct kvm_vcpu *vcpu, uint32_t action, > + uint32_t bitmap) > +{ > + struct incompatible_pmu_event_filter err_f; > + > + err_f.action = action; > + err_f.fixed_counter_bitmap = bitmap; > + ioctl((vcpu->vm)->fd, KVM_SET_PMU_EVENT_FILTER, &err_f.action); This is completely busted. It "passes" by luck, not because it's a valid test. The size of the argument is embedded in the IOCTL number itself, which means that unless glibc is being very nice and using a macro + typeof + sizeof to sanity check things, which I highly doubt is the case, this ioctl() is passing random stack data, a.k.a. garbage, to KVM. In short, drop this patch.