Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp698428ybv; Thu, 13 Feb 2020 07:58:45 -0800 (PST) X-Google-Smtp-Source: APXvYqxEwjjZNYgzer8qm1da1MtxCHNggy3LDnJgfa4SXlB4kWA4fVU3q2h068r80ZLToOrDiyOy X-Received: by 2002:aca:90f:: with SMTP id 15mr3422884oij.18.1581609525080; Thu, 13 Feb 2020 07:58:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581609525; cv=none; d=google.com; s=arc-20160816; b=UmW69fDOPGE9jZ+OCaHoALBQwCyV6wDzi5QIf3igsDygW6ExyuiDFPJjT8sZG29Huj f3C2pwDDO7ZUF1MnekJrAfmMOm3IVsIyeB0iX+pKyKm39rCEwWVQpjIw1W8AmV+ULQU+ kWyqWoO7g3rwGbOH8Mu71cv7+EUSnrwoRz9S1GM9sIxTNeCSkwKECg/2P2gEOIe88lLJ tRawEFjeayfIEJyKRPRHM/AuvTVOyiZhNHYorDlpl7y/lp25i3Ti4Xfg2vAjj8O46guS fXkzdNH6olWveAiTEwxzXI0y56DUkK7ah1BnWqPPpfzD1v6T6AwmJ5gsh2dlPLQN2wP/ a+OQ== 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-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=iHd9eEOMss4ignfVOBjMhQvhmaQpxOZedD/hOOnSljE=; b=iHKbxTtixbhwlk+9QRVqZ6bk28yhRoseey1jy1CY1HY3ixojp8LYXoXILs/QoohxpS L0IX/Th+mlmn08tLI64UW+hm9+ySbhJCrhoesCUq/7IG4pieyDfe530wY2iYg6l0yRhF yvyqyOMOIYH1HTSWncpTkTcroNNLVJILrmIfj9OfoS2Pc7NFMIiYV28WXAHEnfqIxplY 4iQqIC1v/mZjX9vJ273mTU9kxfmBLbPLHB77ba/+wQs+/EaA6lC6W1r3ytQQiiKNnRqQ QaFtAihW5aGddon77gXDrSxHQS5Wq9S/OvKZsWkzo0DpQ5xSR3sqRI5Fcd3ZcUQ5REmD RWdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="aW4NpPK/"; 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 t7si1202433otl.133.2020.02.13.07.58.33; Thu, 13 Feb 2020 07:58:45 -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; dkim=fail header.i=@gmail.com header.s=20161025 header.b="aW4NpPK/"; 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 S2387799AbgBMP5d (ORCPT + 99 others); Thu, 13 Feb 2020 10:57:33 -0500 Received: from mail-ot1-f65.google.com ([209.85.210.65]:44365 "EHLO mail-ot1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727986AbgBMP5V (ORCPT ); Thu, 13 Feb 2020 10:57:21 -0500 Received: by mail-ot1-f65.google.com with SMTP id h9so6000459otj.11 for ; Thu, 13 Feb 2020 07:57:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:reply-to:references :mime-version:content-disposition:in-reply-to:user-agent; bh=iHd9eEOMss4ignfVOBjMhQvhmaQpxOZedD/hOOnSljE=; b=aW4NpPK/CUlNtpEKVSyOptCzOOAEb2UBHdaa2/6OuNkGeDyA/3Ju9hy4bWbsVCTZG2 HcS2gB+D/ewN3JPKxLD9z/UO/hKQLyHqtZSVOrVNmQFS7sd31qPbQHktwPrdzlHoBTaQ ZFHGf/SCImB3lwFh0KIdsJ8b3l2+vU9TRI/9wlxTO9+8s+tdN+BH6p8vuyXjNeSwA7w0 f1BIjIQA9oUVq2/se0P5dfZmzcBbxr+v1zB7PxiKJAEw1l57/9npFLS22goXHfHH3l2j w+WBxEKnHNvvco1oGaxKSTDThGtAQkulVUfNkOtkAgDMGUOeYGWyxz6XOfe5u0o2+AyY o4GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :reply-to:references:mime-version:content-disposition:in-reply-to :user-agent; bh=iHd9eEOMss4ignfVOBjMhQvhmaQpxOZedD/hOOnSljE=; b=fdnAFJeYmt6HJyA4sdVDE2+YQWxV47FB60NE4xwGoirCw7hFwC6JQnxO9RH3ai2cZn CjD/orOzPLBadaDAJFgt5rA4lrtOoZwtPxb06Uy1KaORk1y2VKjiqk+AyKoN+a1P7DaU +M3s9Lusd8cSXH0prTwvEtxbG2c39DcufmaMTHlMQC608bPymx2aQGj5EHjW1ZnnXfUn ujCPMgwteqziM0oM0wc0anTF06vv4KebP6bGJ4w9ZxvvB9cjjHkUEItja2hnjyWk50px zL3Kny+5L+Xk6t3oPMzWA9oER9I5wSQKvEZ/vpMnoE7ONkp10ToaJpCHEQupClPgOvi2 kp1w== X-Gm-Message-State: APjAAAWALjrumX6dAWPknydVSIjstZbE4OkJQf7TuhdmYM85S7pWekKL IEj/Ud0KrIiYtpmk21k4tw== X-Received: by 2002:a9d:7e99:: with SMTP id m25mr13475107otp.212.1581609439644; Thu, 13 Feb 2020 07:57:19 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id m15sm914229otl.20.2020.02.13.07.57.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Feb 2020 07:57:19 -0800 (PST) Received: from minyard.net (unknown [IPv6:2001:470:b8f6:1b:d0c7:64ad:d8cf:b1d2]) by serve.minyard.net (Postfix) with ESMTPSA id 97B2A180053; Thu, 13 Feb 2020 15:57:18 +0000 (UTC) Date: Thu, 13 Feb 2020 09:57:17 -0600 From: Corey Minyard To: Will Deacon Cc: Catalin Marinas , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH 0/2] arm64 kgdb fixes for single stepping Message-ID: <20200213155717.GR7842@minyard.net> Reply-To: minyard@acm.org References: <20200213031131.13255-1-minyard@acm.org> <20200213101057.GB1405@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200213101057.GB1405@willie-the-truck> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 13, 2020 at 10:10:58AM +0000, Will Deacon wrote: > On Wed, Feb 12, 2020 at 09:11:29PM -0600, minyard@acm.org wrote: > > I got a bug report about using kgdb on arm64, and it turns out it was > > fairly broken. Patch 2 has a description of what was going on. I am > > using a Marvell 8100 board. > > > > The following patches fix the problem, but probably not in the > > best way. They are what I hacked out to show the problems. > > > > I am not quite sure how this will interact with kprobes and hardware > > breakpoints which use the same code, but they would have been broken, > > too, so this is not making them any worse. > > This should all be handled by kgdb itself, not by changing the low-level > debug exception handling. For example, the '&kgdb_step_hook' can take > care of re-arming the step state machine and kgdb can also simply disable > interrupts during the step if it doesn't want to step into the handler. How can kgdb disable the SS bit in MDSRC, or re-enable it on the right CPU, without doing this in the exception handling? I'm actually thinking that this may be a hardware bug. Looking at the ARMv8 manual, it looks like PSTATE.SS should be set to 0 if the processor takes an exception. That's definitely not happening; if I do an instruction step from, say, sys_sync(), it gets the single-step trap on the instruction after the PSTATE.D bit is disabled in el1_irq. Even so, I think the migration issue is still a problem. If you do an eret set up for single-step, and interrupts are on, and you get a timer interrupt, it could migrate the task to a different CPU if PREEMPT_ENABLE is set, right? If so, the MDSRC.SS bit will be set on the wrong CPU and the single step trap won't happen. That will break kprobes, too. You mention turning off interrupts in kgdb when single-stepping, which you could do and it would solve this problem. But it wouldn't solve the problem of taking a paging exception, which you want to take in this case. And you could still migrate on a paging exception. So I don't think disabling interrupts is a good solution. I don't see a solution besides clearing MDSCR.SS on an el1 exception entry and conditionally setting it on an el1 exception return. It might be better to have a thread flag to do this instead of depending on the setting of that bit; I'm not sure how expensive accessing the MDSRC register is. Setting SPSR.SS on subsequent single steps is definitely an issue, but I can split that out into a separate patch. -corey > > Will