Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp994625ybi; Wed, 17 Jul 2019 08:02:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqxRuQASCtomRWPK7RRhqGugvS7ILIkU30L710FV99gXau9Hv5S4IXJ0CaGp7sEPRqrxMmOX X-Received: by 2002:a17:90a:26ef:: with SMTP id m102mr43915859pje.50.1563375725215; Wed, 17 Jul 2019 08:02:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563375725; cv=none; d=google.com; s=arc-20160816; b=cxmSGtENkBfQFZ/WndeWmQDwYEOMf/560pG3qCn2aV2Wi1AGcOSm0CGhX2VEMNCqYb ZuhdYBM/NEu/uxHEcpiiOyUbc1rn2YbR4UA6IQJCJY8TVX1KoJnc00TzHFA3vcI8wNrW IuN5sXDSBp8xHnEyIjfbf/zxi+GREjHJTZ5VptXqDJGTsUqZHdgExhlh7prf7/EfYmBZ c+8nmSk0qQajtnxHFQpBG0oCh0Onqhgz83EJzWS1ra0NtxCdr+3O2m5NdNquD4u5aW0O 54zkRjb6t2jBx2Dc47R/WMvd/ZdsWy4NqhSQrYKTGBNhTdtN9zWiAlbyyYbGk4cDKya1 yVmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject; bh=dMA/WKuAn+4bAmOpvBu3JbrdV8SZBxbs5G3WpX24ekA=; b=Z/Z9tZbHpfptbZknPc8aTiJhOS+NI2nZqF2CaIYb+Qm7xseRSHrSMf6aPnxpfjVmDO 61SS7s/FusQHhL9X++Ce4BT9YGLmnmvNep5zr9ftEssF3juiugEZkSqqdRip90CmNK2y fsqJuneSRbIoOrUTUfgiLLrCs1Bw96DCIVppfFcSVSmR5dYNprOU1lhGyAJCfnUHdgG1 W/188/P0XdlZFs+5da5E+DnNqk8HmB1bBjUHpHuS9iv+mkB7C+oF9AULlHg7vIPwdpie c96HDGf18Ypl56aWOd+2WCeoHYH+zeM6gMILDJnhMfHUOHduZih92oCI86B/i0nkdRMO SCnw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l67si23496397plb.370.2019.07.17.08.01.48; Wed, 17 Jul 2019 08:02:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727815AbfGQPAf (ORCPT + 99 others); Wed, 17 Jul 2019 11:00:35 -0400 Received: from foss.arm.com ([217.140.110.172]:48156 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725936AbfGQPAf (ORCPT ); Wed, 17 Jul 2019 11:00:35 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8B405337; Wed, 17 Jul 2019 08:00:34 -0700 (PDT) Received: from [10.1.197.61] (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E0A773F71A; Wed, 17 Jul 2019 08:00:32 -0700 (PDT) Subject: Re: [PATCH] KVM: arm/arm64: Assign pmc->idx before kvm_pmu_stop_counter() To: Julien Thierry , Zenghui Yu , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Cc: marc.zyngier@arm.com, james.morse@arm.com, suzuki.poulose@arm.com, julien.thierry.kdev@gmail.com, linux-kernel@vger.kernel.org, wanghaibin.wang@huawei.com, andrew.murray@arm.com References: <1563366019-31200-1-git-send-email-yuzenghui@huawei.com> <01fa98c1-8274-445c-5e04-219372920ba2@arm.com> From: Marc Zyngier Organization: Approximate Message-ID: <26b64d48-5ff9-7d62-bc44-601fdcc43223@kernel.org> Date: Wed, 17 Jul 2019 16:00:31 +0100 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <01fa98c1-8274-445c-5e04-219372920ba2@arm.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 17/07/2019 14:44, Julien Thierry wrote: > Hi Zenghui, > > On 17/07/2019 13:20, Zenghui Yu wrote: >> We use "pmc->idx" and the "chained" bitmap to determine if the pmc is >> chained, in kvm_pmu_pmc_is_chained(). But idx might be uninitialized >> (and random) when we doing this decision, through a KVM_ARM_VCPU_INIT >> ioctl -> kvm_pmu_vcpu_reset(). And the test_bit() against this random >> idx will potentially hit a KASAN BUG [1]. >> >> Fix it by moving the assignment of idx before kvm_pmu_stop_counter(). >> >> [1] https://www.spinics.net/lists/kvm-arm/msg36700.html >> >> Fixes: 80f393a23be6 ("KVM: arm/arm64: Support chained PMU counters") >> Suggested-by: Andrew Murray >> Cc: Marc Zyngier >> Signed-off-by: Zenghui Yu > --- >> virt/kvm/arm/pmu.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/virt/kvm/arm/pmu.c b/virt/kvm/arm/pmu.c >> index 3dd8238..521bfdd 100644 >> --- a/virt/kvm/arm/pmu.c >> +++ b/virt/kvm/arm/pmu.c >> @@ -225,8 +225,8 @@ void kvm_pmu_vcpu_reset(struct kvm_vcpu *vcpu) >> struct kvm_pmu *pmu = &vcpu->arch.pmu; >> >> for (i = 0; i < ARMV8_PMU_MAX_COUNTERS; i++) { >> - kvm_pmu_stop_counter(vcpu, &pmu->pmc[i]); >> pmu->pmc[i].idx = i; > > Yes, this is kind of a static property that should really be part of a > "kvm_pmu_vcpu_init()" or "kvm_pmu_vcpu_create()" and is not expected to > be modified across resets... > > There is no such function at the time and I'm unsure whether this > warrants creating that separate function (I would still suggest creating > it to make things clearer). Yup, that's pretty bad, now that you mention it. I'd be all for the introduction of kvm_pmu_vcpu_init(), given that we already have kvm_pmu_vcpu_destroy(). > >> + kvm_pmu_stop_counter(vcpu, &pmu->pmc[i]); > > Whatever other opinions are on splitting pmu_vcpu_init/reset, that > change makes sense and fixes the issue: > > Acked-by: Julien Thierry > >> } >> >> bitmap_zero(vcpu->arch.pmu.chained, ARMV8_PMU_MAX_COUNTER_PAIRS); >> > > Cheers, > Zenghui, could you please update your patch to take the above into account? Thanks, M. -- Jazz is not dead, it just smells funny...