All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Greg KH <greg@kroah.com>, Ingo Molnar <mingo@elte.hu>,
	Jesse Barnes <jbarnes@virtuousgeek.org>,
	Len Brown <lenb@kernel.org>, LKML <linux-kernel@vger.kernel.org>,
	Takashi Iwai <tiwai@suse.de>,
	Andrew Morton <akpm@linux-foundation.org>,
	pm list <linux-pm@lists.linux-foundation.org>
Subject: Re: [PATCH 1/3] PCI: Rework default handling of suspend and resume
Date: Sun, 7 Dec 2008 22:02:58 +0100	[thread overview]
Message-ID: <200812072202.58618.rjw@sisk.pl> (raw)
In-Reply-To: <alpine.LFD.2.00.0812070835040.3425@nehalem.linux-foundation.org>

On Sunday, 7 of December 2008, Linus Torvalds wrote:
> 
> On Sun, 7 Dec 2008, Rafael J. Wysocki wrote:
> > 
> > If there is no objection from Jesse and if you don't mind, I'll prepare a
> > version of the $subject patch on top of the patch in your tree and send it to
> > you.
> 
> Rafael: there's a bug in your 1/3 patch. 
> 
> It looks like "pci_save_state()" is currently unhappy with being called 
> with interrupts disabled. Or at least "pci_save_pci[ex]_state()" state 
> are. They both do a kzalloc(GFP_KERNEL).
> 
> So you should change that GFP_KERNEL into a GFP_ATOMIC. Or do something 
> more complicated like pre-allocate them during early suspend, but just 
> changing it to GFP_ATOMIC seems to be the trivial fix.
> 
> I'm not seeing any other issues with saving/restoring things with irq's 
> disabled, but people should be on the lookout for details like this.

I overlooked that, sorry.

What about doing the following in addition to patch [1/3]?

Rafael

---
 drivers/pci/pci.c   |   73 ++++++++++++++++++++++++++++++++++++----------------
 drivers/pci/pci.h   |    1 
 drivers/pci/probe.c |    3 ++
 3 files changed, 55 insertions(+), 22 deletions(-)

Index: linux-2.6/drivers/pci/probe.c
===================================================================
--- linux-2.6.orig/drivers/pci/probe.c
+++ linux-2.6/drivers/pci/probe.c
@@ -958,6 +958,9 @@ static void pci_init_capabilities(struct
 	/* MSI/MSI-X list */
 	pci_msi_init_pci_dev(dev);
 
+	/* Buffers for saving PCIe and PCI-X capabilities */
+	pci_allocate_cap_save_buffers(dev);
+
 	/* Power Management */
 	pci_pm_init(dev);
 
Index: linux-2.6/drivers/pci/pci.h
===================================================================
--- linux-2.6.orig/drivers/pci/pci.h
+++ linux-2.6/drivers/pci/pci.h
@@ -41,6 +41,7 @@ struct pci_platform_pm_ops {
 
 extern int pci_set_platform_pm(struct pci_platform_pm_ops *ops);
 extern void pci_pm_init(struct pci_dev *dev);
+extern void pci_allocate_cap_save_buffers(struct pci_dev *dev);
 
 extern int pci_user_read_config_byte(struct pci_dev *dev, int where, u8 *val);
 extern int pci_user_read_config_word(struct pci_dev *dev, int where, u16 *val);
Index: linux-2.6/drivers/pci/pci.c
===================================================================
--- linux-2.6.orig/drivers/pci/pci.c
+++ linux-2.6/drivers/pci/pci.c
@@ -640,19 +640,14 @@ static int pci_save_pcie_state(struct pc
 	int pos, i = 0;
 	struct pci_cap_saved_state *save_state;
 	u16 *cap;
-	int found = 0;
 
 	pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
 	if (pos <= 0)
 		return 0;
 
 	save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP);
-	if (!save_state)
-		save_state = kzalloc(sizeof(*save_state) + sizeof(u16) * 4, GFP_KERNEL);
-	else
-		found = 1;
 	if (!save_state) {
-		dev_err(&dev->dev, "out of memory in pci_save_pcie_state\n");
+		dev_err(&dev->dev, "buffer not found in %s\n", __FUNCTION__);
 		return -ENOMEM;
 	}
 	cap = (u16 *)&save_state->data[0];
@@ -661,9 +656,7 @@ static int pci_save_pcie_state(struct pc
 	pci_read_config_word(dev, pos + PCI_EXP_LNKCTL, &cap[i++]);
 	pci_read_config_word(dev, pos + PCI_EXP_SLTCTL, &cap[i++]);
 	pci_read_config_word(dev, pos + PCI_EXP_RTCTL, &cap[i++]);
-	save_state->cap_nr = PCI_CAP_ID_EXP;
-	if (!found)
-		pci_add_saved_cap(dev, save_state);
+
 	return 0;
 }
 
@@ -688,30 +681,21 @@ static void pci_restore_pcie_state(struc
 
 static int pci_save_pcix_state(struct pci_dev *dev)
 {
-	int pos, i = 0;
+	int pos;
 	struct pci_cap_saved_state *save_state;
-	u16 *cap;
-	int found = 0;
 
 	pos = pci_find_capability(dev, PCI_CAP_ID_PCIX);
 	if (pos <= 0)
 		return 0;
 
 	save_state = pci_find_saved_cap(dev, PCI_CAP_ID_PCIX);
-	if (!save_state)
-		save_state = kzalloc(sizeof(*save_state) + sizeof(u16), GFP_KERNEL);
-	else
-		found = 1;
 	if (!save_state) {
-		dev_err(&dev->dev, "out of memory in pci_save_pcie_state\n");
+		dev_err(&dev->dev, "buffer not found in %s\n", __FUNCTION__);
 		return -ENOMEM;
 	}
-	cap = (u16 *)&save_state->data[0];
 
-	pci_read_config_word(dev, pos + PCI_X_CMD, &cap[i++]);
-	save_state->cap_nr = PCI_CAP_ID_PCIX;
-	if (!found)
-		pci_add_saved_cap(dev, save_state);
+	pci_read_config_word(dev, pos + PCI_X_CMD, (u16 *)save_state->data);
+
 	return 0;
 }
 
@@ -1301,6 +1285,51 @@ void pci_pm_init(struct pci_dev *dev)
 }
 
 /**
+ * pci_add_save_buffer - allocate buffer for saving given capability registers
+ * @dev: the PCI device
+ * @cap: the capability to allocate the buffer for
+ * @size: requested size of the buffer
+ */
+static int pci_add_cap_save_buffer(
+	struct pci_dev *dev, char cap, unsigned int size)
+{
+	int pos;
+	struct pci_cap_saved_state *save_state;
+
+	pos = pci_find_capability(dev, cap);
+	if (pos <= 0)
+		return 0;
+
+	save_state = kzalloc(sizeof(*save_state) + size, GFP_KERNEL);
+	if (!save_state)
+		return -ENOMEM;
+
+	save_state->cap_nr = cap;
+	pci_add_saved_cap(dev, save_state);
+
+	return 0;
+}
+
+/**
+ * pci_allocate_cap_save_buffers - allocate buffers for saving capabilities
+ * @dev: the PCI device
+ */
+void pci_allocate_cap_save_buffers(struct pci_dev *dev)
+{
+	int error;
+
+	error = pci_add_cap_save_buffer(dev, PCI_CAP_ID_EXP, 4 * sizeof(u16));
+	if (error)
+		dev_err(&dev->dev,
+			"unable to preallocate PCI Express save buffer\n");
+
+	error = pci_add_cap_save_buffer(dev, PCI_CAP_ID_PCIX, sizeof(u16));
+	if (error)
+		dev_err(&dev->dev,
+			"unable to preallocate PCI-X save buffer\n");
+}
+
+/**
  * pci_enable_ari - enable ARI forwarding if hardware support it
  * @dev: the PCI device
  */

  parent reply	other threads:[~2008-12-07 21:04 UTC|newest]

Thread overview: 185+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-02  2:20 Regression from 2.6.26: Hibernation (possibly suspend) broken on Toshiba R500 (bisected) Rafael J. Wysocki
2008-12-02  3:32 ` Linus Torvalds
2008-12-02  3:42   ` Linus Torvalds
2008-12-02  4:31     ` Frans Pop
2008-12-02  4:46       ` Linus Torvalds
2008-12-02  5:29         ` Frans Pop
2008-12-02  5:56           ` Frans Pop
2008-12-02 15:46           ` Linus Torvalds
2008-12-02 17:46             ` Frans Pop
2008-12-02 18:17               ` Linus Torvalds
2008-12-05  8:53             ` MSI changes in .28 Frans Pop
2008-12-05  9:09               ` Yinghai Lu
2008-12-05 12:20               ` Ingo Molnar
2008-12-05 13:04                 ` Eric Dumazet
2008-12-05 17:49                 ` H. Peter Anvin
2008-12-02  4:13   ` Regression from 2.6.26: Hibernation (possibly suspend) broken on Toshiba R500 (bisected) Frans Pop
2008-12-02  4:36     ` Linus Torvalds
2008-12-02 22:38       ` Rafael J. Wysocki
2008-12-02 23:37         ` Linus Torvalds
2008-12-03  0:00           ` Rafael J. Wysocki
2008-12-03  0:05             ` Rafael J. Wysocki
2008-12-03  0:31             ` Rafael J. Wysocki
2008-12-03  0:41             ` Linus Torvalds
2008-12-03  1:22               ` Rafael J. Wysocki
2008-12-03  2:02                 ` Linus Torvalds
2008-12-03  7:40                   ` Rafael J. Wysocki
2008-12-03  7:52                     ` Rafael J. Wysocki
2008-12-03 11:20                       ` Rafael J. Wysocki
2008-12-03 15:53                         ` Linus Torvalds
2008-12-04  1:23                           ` Rafael J. Wysocki
2008-12-04  4:40                             ` Linus Torvalds
2008-12-04  8:21                               ` Frans Pop
2008-12-04 22:01                               ` Rafael J. Wysocki
2008-12-04 11:29                           ` Frans Pop
2008-12-04 16:17                             ` Linus Torvalds
2008-12-04 18:00                               ` Frans Pop
2008-12-04 20:03                                 ` Linus Torvalds
2008-12-05 21:26                                   ` Linus Torvalds
2008-12-05 22:01                                     ` Rafael J. Wysocki
2008-12-05 22:14                                       ` Linus Torvalds
2008-12-06  0:04                                         ` Rafael J. Wysocki
2008-12-06  0:50                                           ` Linus Torvalds
2008-12-06  1:18                                             ` Rafael J. Wysocki
2008-12-06  1:55                                               ` Linus Torvalds
2008-12-06  2:18                                                 ` Rafael J. Wysocki
2008-12-06 13:53                                                   ` Rafael J. Wysocki
2008-12-06  2:45                                                 ` Greg KH
2009-01-28 12:00                                     ` Frans Pop
2009-01-29 14:11                                       ` Ingo Molnar
2009-01-29 14:48                                         ` Rafael J. Wysocki
2009-01-29 16:44                                           ` Alexey Starikovskiy
2009-01-30  4:35                                         ` Frans Pop
2008-12-06  9:20                                   ` [patch,rfc] usb: restore config before enabling device on resume Frans Pop
2008-12-06 13:48                                     ` Rafael J. Wysocki
2008-12-06 15:02                                       ` Frans Pop
2008-12-10 14:06                                   ` "APIC error on CPU1: 00(40)" during resume (was: Regression from 2.6.26: Hibernation (possibly suspend) broken on Toshiba R500) Frans Pop
2008-12-10 15:51                                     ` Linus Torvalds
2008-12-10 16:05                                       ` Frans Pop
2008-12-10 16:26                                         ` Linus Torvalds
2008-12-10 16:52                                           ` Matthew Garrett
2008-12-10 17:13                                             ` Linus Torvalds
2008-12-10 17:33                                           ` Ingo Molnar
2008-12-10 18:41                                             ` Maxim Levitsky
2008-12-20 21:31                                             ` "APIC error on CPU1: 00(40)" during resume Frans Pop
2008-12-21  8:29                                               ` Ingo Molnar
2008-12-23  4:28                                                 ` Len Brown
2008-12-04 22:46                                 ` Regression from 2.6.26: Hibernation (possibly suspend) broken on Toshiba R500 (bisected) Rafael J. Wysocki
2008-12-04 22:40                               ` Rafael J. Wysocki
2008-12-04 23:22                                 ` Linus Torvalds
2008-12-04 23:45                                   ` Rafael J. Wysocki
2008-12-05  0:07                                     ` Linus Torvalds
2008-12-05  0:20                                       ` Rafael J. Wysocki
2008-12-05  6:55                                     ` Frans Pop
2008-12-04 22:09                             ` Rafael J. Wysocki
2008-12-04 22:20                               ` Linus Torvalds
2008-12-04 23:31                                 ` Rafael J. Wysocki
2008-12-05  0:03                                   ` Linus Torvalds
2008-12-05  0:45                                     ` Linus Torvalds
2008-12-05  1:08                                       ` Rafael J. Wysocki
2008-12-05  1:45                                         ` Linus Torvalds
2008-12-05  2:55                                           ` Linus Torvalds
2008-12-05  3:25                                             ` Linus Torvalds
2008-12-05  6:44                                               ` Frans Pop
2008-12-05  8:27                                                 ` Frans Pop
2008-12-05 12:00                                               ` Rafael J. Wysocki
2008-12-05 15:57                                                 ` Linus Torvalds
2008-12-05 21:32                                                   ` Rafael J. Wysocki
2008-12-05 17:25                                               ` Jesse Barnes
2008-12-02 15:49   ` Rafael J. Wysocki
2008-12-06 14:05 ` [PATCH 0/3] Fix hibernation regression on Toshiba Portege R500 Rafael J. Wysocki
2008-12-06 14:07   ` [PATCH 1/3] PCI: Rework default handling of suspend and resume Rafael J. Wysocki
2008-12-06 14:07     ` Rafael J. Wysocki
2008-12-06 17:07     ` Linus Torvalds
2008-12-06 17:07     ` Linus Torvalds
2008-12-06 17:22       ` Rafael J. Wysocki
2008-12-06 17:22       ` Rafael J. Wysocki
2008-12-06 17:33         ` Linus Torvalds
2008-12-06 17:43           ` Rafael J. Wysocki
2008-12-06 17:43           ` Rafael J. Wysocki
2008-12-06 18:00             ` Linus Torvalds
2008-12-06 18:00               ` Linus Torvalds
2008-12-06 21:24               ` Rafael J. Wysocki
2008-12-06 21:24               ` Rafael J. Wysocki
2008-12-07  4:44               ` Jesse Barnes
2008-12-07  4:44               ` Jesse Barnes
2008-12-07  5:41               ` Greg KH
2008-12-07 12:47                 ` Rafael J. Wysocki
2008-12-07 12:47                 ` Rafael J. Wysocki
2008-12-07 16:44                   ` Linus Torvalds
2008-12-07 16:44                   ` Linus Torvalds
2008-12-07 21:02                     ` Rafael J. Wysocki
2008-12-07 21:02                     ` Rafael J. Wysocki [this message]
2008-12-07 17:26                   ` Greg KH
2008-12-07 17:26                   ` Greg KH
2008-12-07 23:34                     ` [PATCH 1/3] PCI: Rework default handling of suspend and resume (rebased) Rafael J. Wysocki
2008-12-07 23:34                     ` Rafael J. Wysocki
2008-12-07  5:41               ` [PATCH 1/3] PCI: Rework default handling of suspend and resume Greg KH
2008-12-06 18:30             ` Alan Stern
2008-12-06 18:30             ` [linux-pm] " Alan Stern
2008-12-06 21:36               ` Rafael J. Wysocki
2008-12-06 21:36                 ` [linux-pm] " Rafael J. Wysocki
2008-12-06 22:24                 ` Linus Torvalds
2008-12-06 22:24                 ` [linux-pm] " Linus Torvalds
2008-12-06 23:25                   ` Arjan van de Ven
2008-12-06 23:25                   ` [linux-pm] " Arjan van de Ven
2008-12-06 23:35                     ` Alan Cox
2008-12-06 23:35                     ` Alan Cox
2008-12-07  6:00                     ` [linux-pm] " Linus Torvalds
2008-12-07  6:03                       ` Linus Torvalds
2008-12-07 13:39                         ` Rafael J. Wysocki
2008-12-07 13:39                         ` [linux-pm] " Rafael J. Wysocki
2008-12-07 16:34                           ` Linus Torvalds
2008-12-07 16:34                           ` [linux-pm] " Linus Torvalds
2008-12-14  9:28                             ` Pavel Machek
2008-12-14  9:28                             ` [linux-pm] " Pavel Machek
2008-12-07 17:18                           ` Arjan van de Ven
2008-12-07 17:18                           ` Arjan van de Ven
2008-12-07  6:03                       ` Linus Torvalds
2008-12-07  9:44                       ` Takashi Iwai
2008-12-07  9:44                       ` [linux-pm] " Takashi Iwai
2008-12-07 12:30                         ` Rafael J. Wysocki
2008-12-07  6:00                     ` Linus Torvalds
2008-12-07  0:02                 ` Alan Stern
2008-12-07  0:02                 ` [linux-pm] " Alan Stern
2008-12-07 13:14                   ` Rafael J. Wysocki
2008-12-07 13:14                     ` [linux-pm] " Rafael J. Wysocki
2008-12-08 22:13                 ` USB suspend and resume for PCI host controllers Alan Stern
2008-12-06 21:09             ` [PATCH 1/3] PCI: Rework default handling of suspend and resume Alan Cox
2008-12-06 21:09               ` Alan Cox
2008-12-06 21:50               ` Rafael J. Wysocki
2008-12-06 21:50               ` Rafael J. Wysocki
2008-12-06 17:33         ` Linus Torvalds
2008-12-06 14:07   ` [PATCH 2/3] PCI: Suspend and resume PCI Express ports with interrupts disabled Rafael J. Wysocki
2008-12-06 14:07   ` Rafael J. Wysocki
2008-12-06 17:15     ` Linus Torvalds
2008-12-06 17:25       ` Rafael J. Wysocki
2008-12-06 17:25       ` Rafael J. Wysocki
2008-12-06 17:38         ` Linus Torvalds
2008-12-06 17:46           ` Rafael J. Wysocki
2008-12-06 17:46           ` Rafael J. Wysocki
2008-12-07  2:18             ` Jesse Barnes
2008-12-07  2:18             ` Jesse Barnes
2008-12-07 12:53               ` Rafael J. Wysocki
2008-12-07 12:53               ` Rafael J. Wysocki
2008-12-06 17:38         ` Linus Torvalds
2008-12-06 17:15     ` Linus Torvalds
2008-12-06 14:09   ` [PATCH 3/3] Sound (HDA Intel): Restore PCI configuration space with interrupts off Rafael J. Wysocki
2008-12-06 14:09   ` Rafael J. Wysocki
2008-12-07  4:45     ` Jesse Barnes
2008-12-07  4:45     ` Jesse Barnes
2008-12-07  9:47       ` Takashi Iwai
2008-12-07  9:47       ` Takashi Iwai
2008-12-11  7:07         ` Takashi Iwai
2008-12-11 20:03           ` Rafael J. Wysocki
2008-12-11 20:27             ` Takashi Iwai
2008-12-11 20:27             ` Takashi Iwai
2008-12-11 20:38               ` Rafael J. Wysocki
2008-12-11 20:38               ` Rafael J. Wysocki
2008-12-12  6:32                 ` Takashi Iwai
2008-12-12  6:32                 ` Takashi Iwai
2008-12-11 20:03           ` Rafael J. Wysocki
2008-12-11  7:07         ` Takashi Iwai
2008-12-06 19:30   ` [PATCH 0/3] Fix hibernation regression on Toshiba Portege R500 Frans Pop
2008-12-06 19:30   ` Frans Pop
2008-12-06 14:05 ` Rafael J. Wysocki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200812072202.58618.rjw@sisk.pl \
    --to=rjw@sisk.pl \
    --cc=akpm@linux-foundation.org \
    --cc=greg@kroah.com \
    --cc=jbarnes@virtuousgeek.org \
    --cc=lenb@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@lists.linux-foundation.org \
    --cc=mingo@elte.hu \
    --cc=tiwai@suse.de \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.