public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
From: "Kok, Auke" <auke-jan.h.kok@intel.com>
To: "Eric W. Biederman" <ebiederm@xmission.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>
Cc: "Kok, Auke" <auke-jan.h.kok@intel.com>,
	Michal Piotrowski <michal.k.k.piotrowski@gmail.com>,
	Jeff Garzik <jeff@garzik.org>,
	Greg Kroah-Hartman <gregkh@suse.de>,
	linux-pm@lists.osdl.org,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Adrian Bunk <bunk@stusta.de>,
	michael@ellerman.id.au, linux-pci@atrey.karlin.mff.cuni.cz,
	Pavel Machek <pavel@ucw.cz>, Jens Axboe <jens.axboe@oracle.com>,
	"Michael S. Tsirkin" <mst@mellanox.co.il>,
	Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@elte.hu>
Subject: Re: [PATCH 2/2] pci: Repair pci_save/restore_state so we can restore one save many times.
Date: Mon, 12 Mar 2007 15:46:44 -0700	[thread overview]
Message-ID: <45F5D854.5020100@intel.com> (raw)
In-Reply-To: <m1lki75wlm.fsf_-_@ebiederm.dsl.xmission.com>

Eric W. Biederman wrote:
> Because we do not reserve space for the pci-x and pci-e state in struct
> pci dev we need to dynamically allocate it.  However because we need
> to support restore being called multiple times after a single save
> it is never safe to free the buffers we have allocated to hold the
> state.
> 
> So this patch modifies the save routines to first check to see
> if we have already allocated a state buffer before allocating
> a new one.  Then the restore routines are modified to not free
> the state after restoring it.  Simple and it fixes some subtle
> error path handling bugs, that are hard to test for.
> 
> Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>


I tested this patch and the other 2 in this series:

[PATCH 0/2] Repair pci_restore_state when used with device resets
[PATCH 1/2] msi: Safer state caching.

against e1000 with suspend/resume functionality. Apart from a minor symmetry 
violation in e1000 for which I will send a patch later, these patches appear to 
work fine on my ich8 with 5 msi capable e1000 ports.

Feel free to add my Signed-off-by: Auke Kok <auke-jan.h.kok@intel.com>

Cheers,

Auke



> ---
>  drivers/pci/pci.c   |   12 ++++++------
>  include/linux/pci.h |    5 -----
>  2 files changed, 6 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 6fb78df..b292c9a 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -551,7 +551,9 @@ static int pci_save_pcie_state(struct pci_dev *dev)
>  	if (pos <= 0)
>  		return 0;
>  
> -	save_state = kzalloc(sizeof(*save_state) + sizeof(u16) * 4, GFP_KERNEL);
> +	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);
>  	if (!save_state) {
>  		dev_err(&dev->dev, "Out of memory in pci_save_pcie_state\n");
>  		return -ENOMEM;
> @@ -582,8 +584,6 @@ static void pci_restore_pcie_state(struct pci_dev *dev)
>  	pci_write_config_word(dev, pos + PCI_EXP_LNKCTL, cap[i++]);
>  	pci_write_config_word(dev, pos + PCI_EXP_SLTCTL, cap[i++]);
>  	pci_write_config_word(dev, pos + PCI_EXP_RTCTL, cap[i++]);
> -	pci_remove_saved_cap(save_state);
> -	kfree(save_state);
>  }
>  
>  
> @@ -597,7 +597,9 @@ static int pci_save_pcix_state(struct pci_dev *dev)
>  	if (pos <= 0)
>  		return 0;
>  
> -	save_state = kzalloc(sizeof(*save_state) + sizeof(u16), GFP_KERNEL);
> +	save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP);
> +	if (!save_state)
> +		save_state = kzalloc(sizeof(*save_state) + sizeof(u16), GFP_KERNEL);
>  	if (!save_state) {
>  		dev_err(&dev->dev, "Out of memory in pci_save_pcie_state\n");
>  		return -ENOMEM;
> @@ -622,8 +624,6 @@ static void pci_restore_pcix_state(struct pci_dev *dev)
>  	cap = (u16 *)&save_state->data[0];
>  
>  	pci_write_config_word(dev, pos + PCI_X_CMD, cap[i++]);
> -	pci_remove_saved_cap(save_state);
> -	kfree(save_state);
>  }
>  
>  
> diff --git a/include/linux/pci.h b/include/linux/pci.h
> index 78417e4..481ea06 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
> @@ -209,11 +209,6 @@ static inline void pci_add_saved_cap(struct pci_dev *pci_dev,
>  	hlist_add_head(&new_cap->next, &pci_dev->saved_cap_space);
>  }
>  
> -static inline void pci_remove_saved_cap(struct pci_cap_saved_state *cap)
> -{
> -	hlist_del(&cap->next);
> -}
> -
>  /*
>   *  For PCI devices, the region numbers are assigned this way:
>   *

  reply	other threads:[~2007-03-12 22:46 UTC|newest]

Thread overview: 104+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <Pine.LNX.4.64.0702202043280.4043@woody.linux-foundation.org>
2007-02-25 17:52 ` 2.6.21-rc1: known regressions (part 1) Adrian Bunk
2007-02-28 18:16   ` Karasyov, Konstantin A
2007-02-25 17:55 ` 2.6.21-rc1: known regressions (part 2) Adrian Bunk
2007-02-27 10:02   ` Jens Axboe
2007-02-27 10:21     ` Pavel Machek
2007-02-27 10:30       ` Jens Axboe
2007-02-27 10:34         ` Ingo Molnar
2007-02-27 10:59           ` Jens Axboe
2007-02-27 11:15             ` Jens Axboe
2007-02-27 13:09               ` Jens Axboe
2007-03-01  9:34               ` Ingo Molnar
2007-03-01 10:41                 ` Ingo Molnar
2007-03-01 14:52                   ` Ingo Molnar
2007-03-01 16:12                     ` Rafael J. Wysocki
2007-03-02  0:26                     ` Linus Torvalds
2007-03-02  0:41                       ` Linus Torvalds
2007-03-02  7:14                       ` Ingo Molnar
2007-03-02  7:21                       ` Ingo Molnar
2007-03-02  8:04                         ` Ingo Molnar
2007-03-02 10:20                           ` Ingo Molnar
2007-03-02 10:22                             ` [patch] KVM: T60 resume fix Ingo Molnar
2007-03-02 11:39                               ` Michael S. Tsirkin
2007-03-03  8:22                                 ` Avi Kivity
2007-03-03  8:21                               ` Avi Kivity
2007-03-03 11:57                                 ` Andrew Morton
2007-03-03 12:07                                   ` Junio C Hamano
2007-03-05  8:22                                 ` Ingo Molnar
2007-03-05  8:50                                   ` Avi Kivity
2007-03-05  8:44                                     ` Ingo Molnar
2007-03-05  8:57                                       ` Ingo Molnar
2007-03-05  9:27                                         ` Avi Kivity
2007-03-05 10:05                                           ` Ingo Molnar
2007-03-05 10:33                                             ` Avi Kivity
2007-03-05 10:33                                               ` Ingo Molnar
2007-03-05 10:40                                               ` Michael S. Tsirkin
2007-03-05 12:54                                         ` Michael S. Tsirkin
2007-03-05 12:50                                           ` Ingo Molnar
2007-03-05 13:26                                             ` Michael S. Tsirkin
2007-03-05 13:32                                               ` Ingo Molnar
2007-03-05 10:23                               ` Michael S. Tsirkin
2007-03-05 10:29                                 ` Ingo Molnar
2007-03-05 15:44                           ` 2.6.21-rc1: known regressions (part 2) Michael S. Tsirkin
2007-03-05 16:14                           ` Michael S. Tsirkin
2007-03-05 16:41                             ` Ingo Molnar
2007-03-05 18:16                             ` Jens Axboe
2007-03-01 23:36                   ` Linus Torvalds
2007-03-02 10:07                 ` Pavel Machek
2007-03-05  8:42                   ` Michael S. Tsirkin
2007-03-05 10:11                     ` SATA resume slowness, e1000 MSI warning Ingo Molnar
2007-03-06  5:30                       ` Jeff Garzik
2007-03-06  6:35                         ` Kok, Auke
2007-03-06  9:04                           ` Ingo Molnar
2007-03-06 15:34                             ` Kok, Auke
2007-03-07  4:15                               ` Eric W. Biederman
2007-03-07 16:31                                 ` Kok, Auke
2007-03-07 16:45                                   ` Kok, Auke
2007-03-07 19:28                                     ` Eric W. Biederman
2007-03-08  2:53                                       ` Andrew Morton
2007-03-08  6:58                                         ` Eric W. Biederman
2007-03-08  9:55                                           ` Jeff Garzik
2007-03-08 17:27                                             ` Eric W. Biederman
2007-03-08 19:58                                               ` [PATCH 0/2] Repair pci_restore_state when used with device resets Eric W. Biederman
2007-03-08 20:04                                                 ` [PATCH 1/2] msi: Safer state caching Eric W. Biederman
2007-03-08 20:06                                                   ` [PATCH 2/2] pci: Repair pci_save/restore_state so we can restore one save many times Eric W. Biederman
2007-03-12 22:46                                                     ` Kok, Auke [this message]
2007-03-08 20:08                                                 ` [PATCH 0/2] Repair pci_restore_state when used with device resets Ingo Molnar
2007-03-08 20:26                                                   ` Eric W. Biederman
2007-03-08 10:23                                           ` SATA resume slowness, e1000 MSI warning Michael S. Tsirkin
2007-03-11 11:11                                             ` Eric W. Biederman
2007-03-11 11:24                                               ` Michael S. Tsirkin
2007-03-11 17:37                                                 ` Eric W. Biederman
2007-03-11 18:03                                                   ` Michael S. Tsirkin
2007-03-11 18:27                                                     ` Eric W. Biederman
2007-03-11 18:37                                                       ` Michael S. Tsirkin
2007-03-11 19:50                                                         ` Eric W. Biederman
2007-03-12  4:35                                                           ` Michael S. Tsirkin
2007-04-16 19:56                                                 ` Michael S. Tsirkin
2007-03-09 23:06                                       ` Kok, Auke
2007-03-10  3:41                                         ` Eric W. Biederman
2007-03-06  9:06                       ` Ingo Molnar
2007-03-06 16:26                       ` Thomas Gleixner
2007-03-06 16:52                         ` Linus Torvalds
2007-03-06 17:09                           ` Kok, Auke
2007-03-09  6:44                     ` 2.6.21-rc1: known regressions (part 2) Pavel Machek
2007-03-05 15:34                 ` Michael S. Tsirkin
2007-02-27 22:09     ` Adrian Bunk
2007-02-28  7:41       ` Jens Axboe
2007-02-26 22:01 ` 2.6.21-rc1: known regressions (v2) (part 1) Adrian Bunk
2007-02-27  4:09   ` Sergio Monteiro Basto
2007-02-27 12:50   ` S.Çağlar Onur
2007-02-27 13:25     ` Ismail Dönmez
2007-02-28 21:13   ` Michael S. Tsirkin
2007-02-28 21:27     ` Thomas Gleixner
2007-02-28 21:40       ` Michael S. Tsirkin
2007-03-01  3:45     ` Jeff Chua
2007-03-02 12:26       ` [linux-pm] " Pavel Machek
2007-03-03 11:17         ` Jens Axboe
2007-03-05  0:04       ` Adrian Bunk
2007-03-06  1:32         ` Jeff Chua
2007-03-06 12:03           ` Jeff Chua
2007-03-06 12:08             ` Michael S. Tsirkin
2007-03-06 12:12               ` Jeff Chua
2007-03-19 15:32                 ` Pavel Machek
2007-03-19 21:23                   ` 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=45F5D854.5020100@intel.com \
    --to=auke-jan.h.kok@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=bunk@stusta.de \
    --cc=ebiederm@xmission.com \
    --cc=gregkh@suse.de \
    --cc=jeff@garzik.org \
    --cc=jens.axboe@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@atrey.karlin.mff.cuni.cz \
    --cc=linux-pm@lists.osdl.org \
    --cc=michael@ellerman.id.au \
    --cc=michal.k.k.piotrowski@gmail.com \
    --cc=mingo@elte.hu \
    --cc=mst@mellanox.co.il \
    --cc=pavel@ucw.cz \
    --cc=tglx@linutronix.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox