Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1602997imm; Thu, 12 Jul 2018 04:58:37 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcM9YViGcQHqncVaO4HN6/2BDvHold85xSCKtWImyR447Q8mHjB/cu1QxOEcUiBk/5T6wR+ X-Received: by 2002:a63:4b1f:: with SMTP id y31-v6mr1898699pga.14.1531396717017; Thu, 12 Jul 2018 04:58:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531396716; cv=none; d=google.com; s=arc-20160816; b=DPbpQsir6FXO6dymgupGYki6a/1G8Dpedjca5GvYiXAPpaDC6qBKOxDc+TnoqzTfQ3 mkXApG978zzzacc/6cqKIlUnUE3psRr98UFH+GDY0bdHq1+8HECN9cAluVNLMwf4jz1Y t8AmuyPEazfyjusx5oKSCUPhlQsyl+1RY7zR8BNnFZuC8j8RAQ8cJDKcJbkRNfKkSv6s iIcjHmhKhkJ2VbFPvMyGeFSjSrN5pZe70o5lYrD7ma1r4OEXWmEOjZdIDjd++h6YMIOP BzLN3E1QfDMMtBqQmouq7hzd8w4KP6yu+Ru/AY/nTVu5BZWRM+oNeb8P6bnndbf0YqU8 ciMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date :arc-authentication-results; bh=6WXc1SioA94qXOWuDE9FaR81SzJ3jSnyylViqxJII8Q=; b=WKKJtF6u9gxTrn/pX8MVoGIQ/Q7wnhq7VHw/aQZFj9Hb10U8IGH8vFISSPMU8cSiNX 2iXWaRZq/GtNhwEpEtoNvlqW7se87T9+p1YqLEQaSRoBGWkgMs6d+TgsuxBD3hbBfokP fKWFl6OO65Q346ZRzo4/EGOk0QnGUNc4c55Kd2qmwyc9qAnYzHyn9xFGIwwkSM8Y7Pqk NOTXmVneSlznDqElgjpbwE0yRAPFDLqTOlM4rkra5TtGzSGHO/5e+bugAJf25+Mt1iwm qdGK3BPTRCsMl51BwzvmSuQS7q/OWwgMkDOdyXccjz0IfurTR1EeVqAVqmckIceNCOUp cqog== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h12-v6si22588876pfk.156.2018.07.12.04.58.21; Thu, 12 Jul 2018 04:58:36 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732248AbeGLMGO (ORCPT + 99 others); Thu, 12 Jul 2018 08:06:14 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:50196 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726768AbeGLMGO (ORCPT ); Thu, 12 Jul 2018 08:06:14 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CAAD0ED1; Thu, 12 Jul 2018 04:57:00 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BC41E3F5B1; Thu, 12 Jul 2018 04:56:59 -0700 (PDT) Date: Thu, 12 Jul 2018 12:56:57 +0100 From: Mark Rutland To: Boris Ostrovsky Cc: Peter Zijlstra , linux-kernel@vger.kernel.org, Ingo Molnar , Jin Yao Subject: Re: [RFC PATCH] perf/core: don't sample kernel regs upon skid Message-ID: <20180712115657.jgcxwrgoxuaz6jxq@lakrids.cambridge.arm.com> References: <20180702151250.14536-1-mark.rutland@arm.com> <20180702154655.GR2494@hirez.programming.kicks-ass.net> <20180702160249.qck45h76galxrckn@lakrids.cambridge.arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 09, 2018 at 06:42:29PM -0400, Boris Ostrovsky wrote: > On 07/02/2018 12:02 PM, Mark Rutland wrote: > > On Mon, Jul 02, 2018 at 05:46:55PM +0200, Peter Zijlstra wrote: > >> On Mon, Jul 02, 2018 at 04:12:50PM +0100, Mark Rutland wrote: > >>> +static struct pt_regs *perf_get_sample_regs(struct perf_event *event, > >>> + struct pt_regs *regs) > >>> +{ > >>> + /* > >>> + * Due to interrupt latency (AKA "skid"), we may enter the kernel > >>> + * before taking an overflow, even if the PMU is only counting user > >>> + * events. > >>> + * > >>> + * If we're not counting kernel events, always use the user regs when > >>> + * sampling. > >>> + * > >>> + * TODO: what do we do about sampling a guest's registers? The IP is > >>> + * special-cased, but for the rest of the regs they'll get the > >>> + * user/kernel regs depending on whether exclude_kernel is set, which > >>> + * is nonsensical. > >>> + * > >>> + * We can't get at the full set of regs in all cases (e.g. Xen's PV PMU > >>> + * can't provide the GPRs), so should we just zero the GPRs when in a > >>> + * guest? Or skip outputting the regs in perf_output_sample? > >> Seems daft Xen cannot provide registers; why is that? Boris? > > The xen_pmu_regs structure simply doesn't have them, so I assume there's > > no API to get them. > > > > Given we don't currently sample the guest regs, I'd be tempted to just > > zero them for now, or skip the sample at output time (if that doesn't > > break some other case). > > (Was out on vacation, couldn't respond earlier) > > Yes, PV guests only get a limited set of registers passed to the handler > by the hypervisor. GPRs are not part of this set. > > I think we need do > > diff --git a/arch/x86/xen/pmu.c b/arch/x86/xen/pmu.c > index 7d00d4a..95997e6 100644 > --- a/arch/x86/xen/pmu.c > +++ b/arch/x86/xen/pmu.c > @@ -478,7 +478,7 @@ static void xen_convert_regs(const struct > xen_pmu_regs *xen_regs, >  irqreturn_t xen_pmu_irq_handler(int irq, void *dev_id) >  { >         int err, ret = IRQ_NONE; > -       struct pt_regs regs; > +       struct pt_regs regs = {0}; >         const struct xen_pmu_data *xenpmu_data = get_xenpmu_data(); >         uint8_t xenpmu_flags = get_xenpmu_flags(); > > > Do you want me to submit a separate patch or can you make this part of > yours? I've only just realised that this is an issue today, without my synthezied pt_regs changes. For any PERF_SAMPLE_REGS_* event under Xen, we'll leak uninitialised kernel stack to userspace in the GPR fields. Boris, I think it's worth spinning a patch to address that now, with Cc stable, if you're still happy to do so? Thanks, Mark.