Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3157733pxk; Mon, 21 Sep 2020 06:44:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFA+rDyU5O0kBCPmJ1dHGnkYwbRktHp+0UQh5XgePAJ2dNWAPJoHXyiNS7DnxYwHeDmMUH X-Received: by 2002:a17:906:f950:: with SMTP id ld16mr48802614ejb.489.1600695879121; Mon, 21 Sep 2020 06:44:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600695879; cv=none; d=google.com; s=arc-20160816; b=J+D4UYWJIREs5p2ifr6Wn8v6kZ1lh41spATDH9wOdViiLz+0xbEVkF7Xx/+aEzPtWJ MvsRh1tPZV12IrbxKOZA7qDt4wPfhRla/ga6nwrFXq2dl0HOaX4QKh7o3umfrjvlK3xy Njn7g8IkDx1UiMe9n3M3YyLx8l996yCQJd4eSOd0HFI7jzllCrMxZ99mPBUYqc1sGp1X u67CwV4VMaqa1bHjwKSw/HdSvXAjJVdsDLz3R5sataexiRNDPT8y3mEVh22cbvaGRKyM v6KHQDhcwdX9VPACwgV8eOF4ysYPqOvbyY5zOguNKYMgc4aK0GkN0KGQGcdnbuh9JJHq FMjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=ZXiVs5DXI3vf7OHctNYp/bCqOPGNAz9iuJSk9xzmeZA=; b=umme5M5Ej25olT1iEVRZdZo8hAqAFtwZvytc7pGvb0wOA+/mpH4EEN46ZQRBYILfly spXVpTwYO1KmkZzNX16pRj5quaCyKNaLLFDtERVeB3cGTIWuJeyCjBMiPVdNqVpSVzkY 8g1Vh1yzkRs3T00gNpxjC6xOTcGa3so89GGAU6fnATKlx8XuosLZ8R/EjcfRX/tx+15c DEBJ5W6QmIJuxYyxRHXlPsF8mxhQb+QQO5skz8/qp/NomA324ZI1KWxr0ZjkBJ7hgyyN kieI/2z9D2A/Vk9A16r7/HKBX+3H7AG1q7GUnI/2mtTVEmrFYYVX+ifS0ydDlEgD2a7l 525w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WxRp7fNz; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a42si11225618edf.535.2020.09.21.06.44.15; Mon, 21 Sep 2020 06:44: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=@kernel.org header.s=default header.b=WxRp7fNz; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727085AbgIUNnL (ORCPT + 99 others); Mon, 21 Sep 2020 09:43:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:55992 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726471AbgIUNnJ (ORCPT ); Mon, 21 Sep 2020 09:43:09 -0400 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 335472084C; Mon, 21 Sep 2020 13:43:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600695788; bh=ppWgQwIPJFgXvpl5SyaBDqV8l2T0GGovdfeRTgIHCFU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=WxRp7fNzBJpKQt2ftVmrIe0M00opXLZn+F2d5mDdpSKGn8lUe/l/M4uRs6n6sREdy bW0hA+DLr0AjQqCJBgrHPFgxzbq84ceM4vkef6/Rx84et6Iin19dgiliB/AzP8PonQ 4ut8OFK2UunvFo4cAYtKyJOqaJGFdcG9RYMVTRe0= Date: Mon, 21 Sep 2020 14:43:02 +0100 From: Will Deacon To: Alexandru Elisei Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, mark.rutland@arm.com, maz@kernel.org, catalin.marinas@arm.com, swboyd@chromium.org, sumit.garg@linaro.org, Julien Thierry , Julien Thierry , Marc Zyngier , Will Deacon , James Morse , Suzuki K Pouloze , kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu Subject: Re: [PATCH v6 5/7] KVM: arm64: pmu: Make overflow handler NMI safe Message-ID: <20200921134301.GJ2139@willie-the-truck> References: <20200819133419.526889-1-alexandru.elisei@arm.com> <20200819133419.526889-6-alexandru.elisei@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200819133419.526889-6-alexandru.elisei@arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 19, 2020 at 02:34:17PM +0100, Alexandru Elisei wrote: > From: Julien Thierry > > kvm_vcpu_kick() is not NMI safe. When the overflow handler is called from > NMI context, defer waking the vcpu to an irq_work queue. > > Cc: Julien Thierry > Cc: Marc Zyngier > Cc: Will Deacon > Cc: Mark Rutland > Cc: Catalin Marinas > Cc: James Morse > Cc: Suzuki K Pouloze > Cc: kvm@vger.kernel.org > Cc: kvmarm@lists.cs.columbia.edu > Signed-off-by: Julien Thierry > Signed-off-by: Alexandru Elisei > --- > arch/arm64/kvm/pmu-emul.c | 25 ++++++++++++++++++++++++- > include/kvm/arm_pmu.h | 1 + > 2 files changed, 25 insertions(+), 1 deletion(-) I'd like an Ack from the KVM side on this one, but some minor comments inline. > diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c > index f0d0312c0a55..30268397ed06 100644 > --- a/arch/arm64/kvm/pmu-emul.c > +++ b/arch/arm64/kvm/pmu-emul.c > @@ -433,6 +433,22 @@ void kvm_pmu_sync_hwstate(struct kvm_vcpu *vcpu) > kvm_pmu_update_state(vcpu); > } > > +/** > + * When perf interrupt is an NMI, we cannot safely notify the vcpu corresponding > + * to the event. > + * This is why we need a callback to do it once outside of the NMI context. > + */ > +static void kvm_pmu_perf_overflow_notify_vcpu(struct irq_work *work) > +{ > + struct kvm_vcpu *vcpu; > + struct kvm_pmu *pmu; > + > + pmu = container_of(work, struct kvm_pmu, overflow_work); > + vcpu = kvm_pmc_to_vcpu(&pmu->pmc[0]); Can you spell this kvm_pmc_to_vcpu(pmu->pmc); ? > + > + kvm_vcpu_kick(vcpu); How do we guarantee that the vCPU is still around by the time this runs? Sorry to ask such a horrible question, but I don't see anything associating the workqueue with the lifetime of the vCPU. Will