Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2283382imm; Mon, 28 May 2018 05:21:46 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqQldpp13eIINASPKIygLbQrXPbQB/8fYe58opRg1/2zOOBYxnArzpA0cbbkjT8wgAAkE23 X-Received: by 2002:a17:902:3303:: with SMTP id a3-v6mr13439610plc.209.1527510106908; Mon, 28 May 2018 05:21:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527510106; cv=none; d=google.com; s=arc-20160816; b=ThlDDxw4oenmnzYdu9/OOnv/3JQDZYdVZ+Gm8mCl8LTR3JbQR0zmrSKYgIMG1aHgBZ PZljM5sXDpNCyQQqGmOGh/PSkFa9iBYrBqaQ+790TPqa5KGyqLx8cXmwU1Fath4zX42n gp7xHOp0ENKBZTBLH2HW9ZEVQ5g/eMKIe4HunOTaPotrZnc3vNh4MSy3ybGpRmpLAKLS D2U7Ovwr6zRJ7S87SyHblpYbn3Nza6Qev9bE9GxyUJVSXLg7w/Yh9DTpXN9pzZY+fPIH lvUL8Fh+Kg79Lfp448Me1FoKNM0jcc8g4fWVa4v3/ECw3bYmeBY7FjqSvTqTZBRQO1no QIPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=zAB36RdRcXPKpq1LkR54+XLq+AJDtNxxovNWxDtyroI=; b=fUCvRVLnk81Z255UYMWVyF8hLP7O4k1S8RtsEkB7MgL1l+nHteQlJKZHWc1SMu8FgM 50ZIjwuCtv59JaMuHFhgWNSIFoaVWI+Na9RNspKie9V9Uf5mmpPsC97tjEGLGGGptMCJ Oew8A9UU2ceOruReQNzFgp6Qqmpp/OExTJ4BZVLt4PfnIzZQXqv32dUhsSFacWwQ+33b 1xYxkbEOP4hMek/uXUkzWHy7Nbc1C48+I3igQS28Ec4yENGVGgLVE/AiedHlAnm0eaEK kTo5+VCZ1/Gvheny04YSd5KdTa4z/r2Tb6IPRKYNHFpssTLoXB24763U6j6ee4RPd+vF kUIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QJ0MtTlC; 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 g8-v6si24382586pgr.474.2018.05.28.05.21.32; Mon, 28 May 2018 05:21:46 -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; dkim=pass header.i=@kernel.org header.s=default header.b=QJ0MtTlC; 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 S938728AbeE1MTv (ORCPT + 99 others); Mon, 28 May 2018 08:19:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:49984 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1164907AbeE1LCh (ORCPT ); Mon, 28 May 2018 07:02:37 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (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 664CB2087E; Mon, 28 May 2018 11:02:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527505356; bh=RlsnEuWbTaTZomXi6rFp0woPyGT7tqubtaccA+iQYKM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QJ0MtTlC/fRfhPUG4tNuk7Qz7QAvWEu3HxrXqCDZWa6BWiAUFXJajD8XMf4hoij9z DM9/cKf8QSgbBlpeu6Z6xd68hvgu+pY3Omm2KjodRgQ5JTYQ6Hia8gq47hoPn2q/Ld 8f8dNWGU52IK2EQw8Wv/OWsl/I/OMhvO4z3ebrSc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Rafael J. Wysocki" , Dominik Brodowski , Sasha Levin Subject: [PATCH 4.14 469/496] PCMCIA / PM: Avoid noirq suspend aborts during suspend-to-idle Date: Mon, 28 May 2018 12:04:14 +0200 Message-Id: <20180528100339.669296768@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100319.498712256@linuxfoundation.org> References: <20180528100319.498712256@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: "Rafael J. Wysocki" [ Upstream commit dbdd0f58fd2cdde5cf945c9da67a2d52d32ba550 ] There is a problem with PCMCIA system resume callbacks with respect to suspend-to-idle in which the ->suspend_noirq() callback may be invoked after the ->resume_noirq() one without resuming the system entirely in some cases. This doesn't work for PCMCIA because of the lack of symmetry between its system suspend and system resume "noirq" callbacks. The system resume handling in PCMCIA is split between socket_early_resume() and socket_late_resume() which are called in different phases of system resume and both need to run for socket_suspend() (invoked by the system suspend "noirq" callback) to work. Specifically, socket_suspend() returns an error when called after socket_early_resume() without socket_late_resume(), so if the suspend-to-idle core detects a spurious wakeup event and attempts to put the system back to sleep, that is aborted by the error coming from socket_suspend(). Avoid that by using a new socket state flag, SOCKET_IN_RESUME, to indicate that socket_early_resume() has already run for the socket in which case socket_suspend() will do minimum handling and return 0. This change has been tested on my venerable Toshiba Portege R500 (which is where the problem has been discovered in the first place), but admittedly I have no PCMCIA cards to test along with the socket itself. Fixes: 33e4f80ee69b (ACPI / PM: Ignore spurious SCI wakeups from suspend-to-idle) Signed-off-by: Rafael J. Wysocki [linux@dominikbrodowski.net: follow same codepaths for both suspend variants; call ->suspend()] Signed-off-by: Dominik Brodowski Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/pcmcia/cs.c | 10 +++++++--- drivers/pcmcia/cs_internal.h | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) --- a/drivers/pcmcia/cs.c +++ b/drivers/pcmcia/cs.c @@ -452,17 +452,20 @@ static int socket_insert(struct pcmcia_s static int socket_suspend(struct pcmcia_socket *skt) { - if (skt->state & SOCKET_SUSPEND) + if ((skt->state & SOCKET_SUSPEND) && !(skt->state & SOCKET_IN_RESUME)) return -EBUSY; mutex_lock(&skt->ops_mutex); - skt->suspended_state = skt->state; + /* store state on first suspend, but not after spurious wakeups */ + if (!(skt->state & SOCKET_IN_RESUME)) + skt->suspended_state = skt->state; skt->socket = dead_socket; skt->ops->set_socket(skt, &skt->socket); if (skt->ops->suspend) skt->ops->suspend(skt); skt->state |= SOCKET_SUSPEND; + skt->state &= ~SOCKET_IN_RESUME; mutex_unlock(&skt->ops_mutex); return 0; } @@ -475,6 +478,7 @@ static int socket_early_resume(struct pc skt->ops->set_socket(skt, &skt->socket); if (skt->state & SOCKET_PRESENT) skt->resume_status = socket_setup(skt, resume_delay); + skt->state |= SOCKET_IN_RESUME; mutex_unlock(&skt->ops_mutex); return 0; } @@ -484,7 +488,7 @@ static int socket_late_resume(struct pcm int ret = 0; mutex_lock(&skt->ops_mutex); - skt->state &= ~SOCKET_SUSPEND; + skt->state &= ~(SOCKET_SUSPEND | SOCKET_IN_RESUME); mutex_unlock(&skt->ops_mutex); if (!(skt->state & SOCKET_PRESENT)) { --- a/drivers/pcmcia/cs_internal.h +++ b/drivers/pcmcia/cs_internal.h @@ -70,6 +70,7 @@ struct pccard_resource_ops { /* Flags in socket state */ #define SOCKET_PRESENT 0x0008 #define SOCKET_INUSE 0x0010 +#define SOCKET_IN_RESUME 0x0040 #define SOCKET_SUSPEND 0x0080 #define SOCKET_WIN_REQ(i) (0x0100<<(i)) #define SOCKET_CARDBUS 0x8000