Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp62418ybv; Wed, 5 Feb 2020 01:09:32 -0800 (PST) X-Google-Smtp-Source: APXvYqz8nZfVj/tuzFyxGYKuJbw/9SaqQcUlIP5DHp+p1NSK89iL9lQf/TF+jKjej08sX4zNepZo X-Received: by 2002:a05:6830:1294:: with SMTP id z20mr24620002otp.60.1580893771828; Wed, 05 Feb 2020 01:09:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580893771; cv=none; d=google.com; s=arc-20160816; b=vbtpDwj9GMSOWFlZaVQ7x6hCXuDoYC0Ry073pvWD0UFaZUgcYFlvDtlbpY5USaWNaD nbTwen7jLKY6rwQyB0vYb0wveVMwpOQtwe4l66OBA8wIs534jbuqkliTw2fW8kWZVzno sInhR1oB28ErZqMg/qCheikoMuqCvDZa3Mh8Jsl+lv/CIkLBjAPp5ivlVuakASLKK+vC YYcPCanGy4paiu0Gz/acvUUSIhnQjPy2RlKc72ZHJ4SVhhQTzhb2E1ilEWJgsL7outr+ Dym0Tg4yjHHIYCiaZFKeyXEQKtzr6WZkMK2DOQL2VqrqgKr4WDSrGSP5elnP3ZB1dB8P gSEQ== 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:from:references:cc:to:subject; bh=vEHnE5pGtrfWrYjw7aRqmi32YTuKk+mqe+klMYxSdPY=; b=lrn8aSYHZLCdgExsXhBvSZSG1E1R/K6om59honaGGzv9pggRcU76+Ol1xs8+0kE1qt GkTdntsPT7B10KAQnx+YxrykPHxcrK1ffBP+MdwnHfiIGBVp4Oje6koL4bO3J0XrkLgZ /eOP0xk53JbBJ13GkI4e49jxT23PKeXhht6UWmIJ7xG5dHp6Xiq+LG8FtQuMpfNkgRNz TvMZ+4gW8GKliB1AVeGcVoJ6RAa0y/Lza1iHueamgdtVYleHDMNmnhCzoiUEmAvmyk6E NWPP9xh2mC/0ppPF/VkFQ1oWdVZ5qSRe0SrogxE30EhaOTJ32qht3Vi8ltXFkNWKINiQ ZwlA== 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=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h18si13263111otj.114.2020.02.05.01.09.17; Wed, 05 Feb 2020 01:09:31 -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=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728109AbgBEJGW (ORCPT + 99 others); Wed, 5 Feb 2020 04:06:22 -0500 Received: from bhuna.collabora.co.uk ([46.235.227.227]:50466 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727459AbgBEJGW (ORCPT ); Wed, 5 Feb 2020 04:06:22 -0500 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: eballetbo) with ESMTPSA id DF1EB2756E6 Subject: Re: [PATCH v6] platform/chrome: cros_ec: Query EC protocol version if EC transitions between RO/RW To: Gwendal Grignou , Marek Szyprowski Cc: Yicheng Li , LKML , Benson Leung , Guenter Roeck , Lee Jones , Andy Shevchenko , Jonathan Cameron , Evan Green , Rushikesh S Kadam , Thomas Gleixner References: <20200203225356.203946-1-yichengli@chromium.org> <54cbade6-c552-4877-a8d7-d2be9930cefd@samsung.com> From: Enric Balletbo i Serra Message-ID: Date: Wed, 5 Feb 2020 10:06:16 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.3.0 MIME-Version: 1.0 In-Reply-To: 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 Hi, On 4/2/20 21:40, Gwendal Grignou wrote: > Reviewed-by: Gwendal Grignou > > On Mon, Feb 3, 2020 at 11:30 PM Marek Szyprowski > wrote: >> >> Hi >> >> On 03.02.2020 23:53, Yicheng Li wrote: >>> RO and RW of EC may have different EC protocol version. If EC transitions >>> between RO and RW, but AP does not reboot (this is true for fingerprint >>> microcontroller / cros_fp, but not true for main ec / cros_ec), the AP >>> still uses the protocol version queried before transition, which can >>> cause problems. In the case of fingerprint microcontroller, this causes >>> AP to send the wrong version of EC_CMD_GET_NEXT_EVENT to RO in the >>> interrupt handler, which in turn prevents RO to clear the interrupt >>> line to AP, in an infinite loop. >>> >>> Once an EC_HOST_EVENT_INTERFACE_READY is received, we know that there >>> might have been a transition between RO and RW, so re-query the protocol. >>> >>> Signed-off-by: Yicheng Li >> >> Tested-by: Marek Szyprowski >> >> Works fine on Samsung Exynos-based Chromebooks: Snow, Peach-Pit and >> Peach-Pi. >> Thanks, we will pick this patch once 5.6-rc1 is out. For my own reference: Acked-for-chrome-platform: Enric Balletbo i Serra >>> --- >>> Hi Enric and Marek, >>> >>>> This patch landed recently in linux-next as commit >>>> 241a69ae8ea8e2defec751fe55dac1287aa044b8. Sadly, it causes following >>>> kernel oops on any key press on Samsung Exynos-based Chromebooks (Snow, >>>> Peach-Pit and Peach-Pi): >>> >>>> Many thanks for report the issue, we will take a look ASAP and revert >>>> this commit meanwhile. >>> >>>> Simply removing the BUG_ON() from cros_ec_get_host_event() function >>>> fixes the issue, but I don't know the protocol details to judge if this >>>> is the correct way of fixing it. >>> The issue was those Samsung Chromebooks (Snow, Peach-Pit and Peach-Pi) >>> do not support mkbp events, yet we applied the same thing to them, which >>> we shouldn't. This v6 should fix it: I Just added a check >>> >>> if (ec_dev->mkbp_event_supported) >>> >>> in cros_ec_register(). >>> >>> >>> >>> drivers/platform/chrome/cros_ec.c | 29 +++++++++++++++++++++ >>> include/linux/platform_data/cros_ec_proto.h | 3 +++ >>> 2 files changed, 32 insertions(+) >>> >>> diff --git a/drivers/platform/chrome/cros_ec.c b/drivers/platform/chrome/cros_ec.c >>> index 9b2d07422e17..f16804db805b 100644 >>> --- a/drivers/platform/chrome/cros_ec.c >>> +++ b/drivers/platform/chrome/cros_ec.c >>> @@ -104,6 +104,23 @@ static int cros_ec_sleep_event(struct cros_ec_device *ec_dev, u8 sleep_event) >>> return ret; >>> } >>> >>> +static int cros_ec_ready_event(struct notifier_block *nb, >>> + unsigned long queued_during_suspend, void *_notify) >>> +{ >>> + struct cros_ec_device *ec_dev = container_of(nb, struct cros_ec_device, >>> + notifier_ready); >>> + u32 host_event = cros_ec_get_host_event(ec_dev); >>> + >>> + if (host_event & EC_HOST_EVENT_MASK(EC_HOST_EVENT_INTERFACE_READY)) { >>> + mutex_lock(&ec_dev->lock); >>> + cros_ec_query_all(ec_dev); >>> + mutex_unlock(&ec_dev->lock); >>> + return NOTIFY_OK; >>> + } >>> + >>> + return NOTIFY_DONE; >>> +} >>> + >>> /** >>> * cros_ec_register() - Register a new ChromeOS EC, using the provided info. >>> * @ec_dev: Device to register. >>> @@ -201,6 +218,18 @@ int cros_ec_register(struct cros_ec_device *ec_dev) >>> dev_dbg(ec_dev->dev, "Error %d clearing sleep event to ec", >>> err); >>> >>> + if (ec_dev->mkbp_event_supported) { >>> + /* >>> + * Register the notifier for EC_HOST_EVENT_INTERFACE_READY >>> + * event. >>> + */ >>> + ec_dev->notifier_ready.notifier_call = cros_ec_ready_event; >>> + err = blocking_notifier_chain_register( >>> + &ec_dev->event_notifier, &ec_dev->notifier_ready); >>> + if (err) >>> + return err; >>> + } >>> + >>> dev_info(dev, "Chrome EC device registered\n"); >>> >>> return 0; >>> diff --git a/include/linux/platform_data/cros_ec_proto.h b/include/linux/platform_data/cros_ec_proto.h >>> index 0d4e4aaed37a..a1c545c464e7 100644 >>> --- a/include/linux/platform_data/cros_ec_proto.h >>> +++ b/include/linux/platform_data/cros_ec_proto.h >>> @@ -121,6 +121,8 @@ struct cros_ec_command { >>> * @event_data: Raw payload transferred with the MKBP event. >>> * @event_size: Size in bytes of the event data. >>> * @host_event_wake_mask: Mask of host events that cause wake from suspend. >>> + * @notifier_ready: The notifier_block to let the kernel re-query EC >>> + * communication protocol when the EC sends EC_HOST_EVENT_INTERFACE_READY. >>> * @ec: The platform_device used by the mfd driver to interface with the >>> * main EC. >>> * @pd: The platform_device used by the mfd driver to interface with the >>> @@ -161,6 +163,7 @@ struct cros_ec_device { >>> int event_size; >>> u32 host_event_wake_mask; >>> u32 last_resume_result; >>> + struct notifier_block notifier_ready; >>> >>> /* The platform devices used by the mfd driver */ >>> struct platform_device *ec; >> >> Best regards >> -- >> Marek Szyprowski, PhD >> Samsung R&D Institute Poland >>