Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4396585ybl; Sat, 21 Dec 2019 05:59:43 -0800 (PST) X-Google-Smtp-Source: APXvYqyfxAz5jwSGZKB+j72/p5kezwUVdMDceoumdO4au2zOPe8AKt695oRqpFIJRCics7F2Siz9 X-Received: by 2002:a9d:7410:: with SMTP id n16mr7031808otk.23.1576936783371; Sat, 21 Dec 2019 05:59:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576936783; cv=none; d=google.com; s=arc-20160816; b=VqbTChYsUKLc5hqM6mXOrTFUI/O2nMqDjbRmdo0Kyob4sSPU2GitIp0Hrdl2xsZLcS BkfYqHY8YTaez1+VtzSSYH89O8/i5kA7hAfs7NJKm+8QoctRIMexFMK2Z9wHa6lN4ZmB dZusjjoLfaH4NOmNxBKoPsWuYUcVyfkxvw0VZlVsDiejq1TucmF7or7w95LE/gCqayjL v8bGp/1aUsBZ1hxM082CA/Pwu9R9xTFofEIZ+L4nS8gloQXvfUIi3f6WNSmHvLSRKQ8r 68JYkWnwQ+2gLckocPRQQ11F46poI7umYzTjGQ8FRDQUqf0KGTMw9j7OpkXhMEgHQm5A 9m5A== 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:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=zMxVa/WhVe4XYJ20Bmw4kNERBoLxhVz18prYxedRKnQ=; b=0DHZPaES1X/eAj6HgZFuK8KtgAa9o5K1ZBkEdN6ADUjwATEEz2yenAX7sLQ603v9o6 jHaOAcBdf/tONGtrWgyN9GLTwI6xpNlNXyv7Wu97/7tSkCTavGoXuX7gfTgSgfuDbmcS mZFToS5O498g4MAy4efCRGiPue0vQaAKNjhmpZolQqDzS7Ha3KdDKM+d6wXw0xEGtTmT OJZWy3pdKhGISeKenAU8jOCaATSPA1VwX7+qEAK4CEjCXKXhRGbup3piOFj5J9Kdj1VM 7iTXcHyBj8NVyT2AKUjtCOJyWRFelYp08Xyj7oB5rkdnEwDg67Vo6J1yI72e+RdAFj3q 5zCw== 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 i78si6603918oib.1.2019.12.21.05.59.32; Sat, 21 Dec 2019 05:59:43 -0800 (PST) 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 S1726965AbfLUN6A (ORCPT + 99 others); Sat, 21 Dec 2019 08:58:00 -0500 Received: from inca-roads.misterjones.org ([213.251.177.50]:55558 "EHLO inca-roads.misterjones.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726339AbfLUN57 (ORCPT ); Sat, 21 Dec 2019 08:57:59 -0500 Received: from 78.163-31-62.static.virginmediabusiness.co.uk ([62.31.163.78] helo=why) by cheepnis.misterjones.org with esmtpsa (TLSv1.2:AES256-GCM-SHA384:256) (Exim 4.80) (envelope-from ) id 1iifGW-00047r-QW; Sat, 21 Dec 2019 14:57:57 +0100 Date: Sat, 21 Dec 2019 13:57:55 +0000 From: Marc Zyngier To: Andrew Murray Cc: Catalin Marinas , Will Deacon , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sudeep Holla , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v2 08/18] arm64: KVM: add support to save/restore SPE profiling buffer controls Message-ID: <20191221135755.70a6e8df@why> In-Reply-To: <20191220143025.33853-9-andrew.murray@arm.com> References: <20191220143025.33853-1-andrew.murray@arm.com> <20191220143025.33853-9-andrew.murray@arm.com> Organization: Approximate X-Mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 62.31.163.78 X-SA-Exim-Rcpt-To: andrew.murray@arm.com, catalin.marinas@arm.com, will@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, sudeep.holla@arm.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on cheepnis.misterjones.org); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 20 Dec 2019 14:30:15 +0000 Andrew Murray wrote: > From: Sudeep Holla > > Currently since we don't support profiling using SPE in the guests, > we just save the PMSCR_EL1, flush the profiling buffers and disable > sampling. However in order to support simultaneous sampling both in Is the sampling actually simultaneous? I don't believe so (the whole series would be much simpler if it was). > the host and guests, we need to save and reatore the complete SPE s/reatore/restore/ > profiling buffer controls' context. > > Let's add the support for the same and keep it disabled for now. > We can enable it conditionally only if guests are allowed to use > SPE. > > Signed-off-by: Sudeep Holla > [ Clear PMBSR bit when saving state to prevent spurious interrupts ] > Signed-off-by: Andrew Murray > --- > arch/arm64/kvm/hyp/debug-sr.c | 51 +++++++++++++++++++++++++++++------ > 1 file changed, 43 insertions(+), 8 deletions(-) > > diff --git a/arch/arm64/kvm/hyp/debug-sr.c b/arch/arm64/kvm/hyp/debug-sr.c > index 8a70a493345e..12429b212a3a 100644 > --- a/arch/arm64/kvm/hyp/debug-sr.c > +++ b/arch/arm64/kvm/hyp/debug-sr.c > @@ -85,7 +85,8 @@ > default: write_debug(ptr[0], reg, 0); \ > } > > -static void __hyp_text __debug_save_spe_nvhe(struct kvm_cpu_context *ctxt) > +static void __hyp_text > +__debug_save_spe_nvhe(struct kvm_cpu_context *ctxt, bool full_ctxt) nit: don't split lines like this if you can avoid it. You can put the full_ctxt parameter on a separate line instead. > { > u64 reg; > > @@ -102,22 +103,46 @@ static void __hyp_text __debug_save_spe_nvhe(struct kvm_cpu_context *ctxt) > if (reg & BIT(SYS_PMBIDR_EL1_P_SHIFT)) > return; > > - /* No; is the host actually using the thing? */ > - reg = read_sysreg_s(SYS_PMBLIMITR_EL1); > - if (!(reg & BIT(SYS_PMBLIMITR_EL1_E_SHIFT))) > + /* Save the control register and disable data generation */ > + ctxt->sys_regs[PMSCR_EL1] = read_sysreg_el1(SYS_PMSCR); > + > + if (!ctxt->sys_regs[PMSCR_EL1]) Shouldn't you check the enable bits instead of relying on the whole thing being zero? > return; > > /* Yes; save the control register and disable data generation */ > - ctxt->sys_regs[PMSCR_EL1] = read_sysreg_el1(SYS_PMSCR); You've already saved the control register... > write_sysreg_el1(0, SYS_PMSCR); > isb(); > > /* Now drain all buffered data to memory */ > psb_csync(); > dsb(nsh); > + > + if (!full_ctxt) > + return; > + > + ctxt->sys_regs[PMBLIMITR_EL1] = read_sysreg_s(SYS_PMBLIMITR_EL1); > + write_sysreg_s(0, SYS_PMBLIMITR_EL1); > + > + /* > + * As PMBSR is conditionally restored when returning to the host we > + * must ensure the service bit is unset here to prevent a spurious > + * host SPE interrupt from being raised. > + */ > + ctxt->sys_regs[PMBSR_EL1] = read_sysreg_s(SYS_PMBSR_EL1); > + write_sysreg_s(0, SYS_PMBSR_EL1); > + > + isb(); > + > + ctxt->sys_regs[PMSICR_EL1] = read_sysreg_s(SYS_PMSICR_EL1); > + ctxt->sys_regs[PMSIRR_EL1] = read_sysreg_s(SYS_PMSIRR_EL1); > + ctxt->sys_regs[PMSFCR_EL1] = read_sysreg_s(SYS_PMSFCR_EL1); > + ctxt->sys_regs[PMSEVFR_EL1] = read_sysreg_s(SYS_PMSEVFR_EL1); > + ctxt->sys_regs[PMSLATFR_EL1] = read_sysreg_s(SYS_PMSLATFR_EL1); > + ctxt->sys_regs[PMBPTR_EL1] = read_sysreg_s(SYS_PMBPTR_EL1); > } > > -static void __hyp_text __debug_restore_spe_nvhe(struct kvm_cpu_context *ctxt) > +static void __hyp_text > +__debug_restore_spe_nvhe(struct kvm_cpu_context *ctxt, bool full_ctxt) > { > if (!ctxt->sys_regs[PMSCR_EL1]) > return; > @@ -126,6 +151,16 @@ static void __hyp_text __debug_restore_spe_nvhe(struct kvm_cpu_context *ctxt) > isb(); > > /* Re-enable data generation */ > + if (full_ctxt) { > + write_sysreg_s(ctxt->sys_regs[PMBPTR_EL1], SYS_PMBPTR_EL1); > + write_sysreg_s(ctxt->sys_regs[PMBLIMITR_EL1], SYS_PMBLIMITR_EL1); > + write_sysreg_s(ctxt->sys_regs[PMSFCR_EL1], SYS_PMSFCR_EL1); > + write_sysreg_s(ctxt->sys_regs[PMSEVFR_EL1], SYS_PMSEVFR_EL1); > + write_sysreg_s(ctxt->sys_regs[PMSLATFR_EL1], SYS_PMSLATFR_EL1); > + write_sysreg_s(ctxt->sys_regs[PMSIRR_EL1], SYS_PMSIRR_EL1); > + write_sysreg_s(ctxt->sys_regs[PMSICR_EL1], SYS_PMSICR_EL1); > + write_sysreg_s(ctxt->sys_regs[PMBSR_EL1], SYS_PMBSR_EL1); > + } > write_sysreg_el1(ctxt->sys_regs[PMSCR_EL1], SYS_PMSCR); > } > > @@ -198,7 +233,7 @@ void __hyp_text __debug_restore_host_context(struct kvm_vcpu *vcpu) > guest_ctxt = &vcpu->arch.ctxt; > > if (!has_vhe()) > - __debug_restore_spe_nvhe(host_ctxt); > + __debug_restore_spe_nvhe(host_ctxt, false); > > if (!(vcpu->arch.flags & KVM_ARM64_DEBUG_DIRTY)) > return; > @@ -222,7 +257,7 @@ void __hyp_text __debug_save_host_context(struct kvm_vcpu *vcpu) > > host_ctxt = kern_hyp_va(vcpu->arch.host_cpu_context); > if (!has_vhe()) > - __debug_save_spe_nvhe(host_ctxt); > + __debug_save_spe_nvhe(host_ctxt, false); > } > > void __hyp_text __debug_save_guest_context(struct kvm_vcpu *vcpu) So all of this is for non-VHE. What happens in the VHE case? M. -- Jazz is not dead. It just smells funny...