linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Cyril Bur <cyrilbur@gmail.com>
To: Daniel Axtens <dja@axtens.net>
Cc: linuxppc-dev@ozlabs.org, mikey@neuling.org, imunsie@au.ibm.com
Subject: Re: [PATCH v2 02/10] cxl: Allocate and release the SPA with the AFU
Date: Tue, 11 Aug 2015 13:42:54 +1000	[thread overview]
Message-ID: <20150811134254.0358f0e3@camb691> (raw)
In-Reply-To: <1438061323-20710-3-git-send-email-dja@axtens.net>

On Tue, 28 Jul 2015 15:28:35 +1000
Daniel Axtens <dja@axtens.net> wrote:

> Previously the SPA was allocated and freed upon entering and leaving
> AFU-directed mode. This causes some issues for error recovery - contexts
> hold a pointer inside the SPA, and they may persist after the AFU has
> been detached.
> 
> We would ideally like to allocate the SPA when the AFU is allocated, and
> release it until the AFU is released. However, we don't know how big the
> SPA needs to be until we read the AFU descriptor.
> 
> Therefore, restructure the code:
> 
>  - Allocate the SPA only once, on the first attach.
> 
>  - Release the SPA only when the entire AFU is being released (not
>    detached). Guard the release with a NULL check, so we don't free
>    if it was never allocated (e.g. dedicated mode)
> 

I'm sure you tested this :), looks fine to me, from an outsiders perspective
code appears to do what the commit message says.

Just one super minor question, you do the NULL check in the caller. How obvious
is the error if/when a caller forgets?

Acked-by: Cyril Bur <cyrilbur@gmail.com>

> Signed-off-by: Daniel Axtens <dja@axtens.net>
> ---
>  drivers/misc/cxl/cxl.h    |  3 +++
>  drivers/misc/cxl/native.c | 28 ++++++++++++++++++----------
>  drivers/misc/cxl/pci.c    |  3 +++
>  3 files changed, 24 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/misc/cxl/cxl.h b/drivers/misc/cxl/cxl.h
> index 47eadbcfd379..88a88c445e2a 100644
> --- a/drivers/misc/cxl/cxl.h
> +++ b/drivers/misc/cxl/cxl.h
> @@ -603,6 +603,9 @@ void unregister_cxl_calls(struct cxl_calls *calls);
>  int cxl_alloc_adapter_nr(struct cxl *adapter);
>  void cxl_remove_adapter_nr(struct cxl *adapter);
>  
> +int cxl_alloc_spa(struct cxl_afu *afu);
> +void cxl_release_spa(struct cxl_afu *afu);
> +
>  int cxl_file_init(void);
>  void cxl_file_exit(void);
>  int cxl_register_adapter(struct cxl *adapter);
> diff --git a/drivers/misc/cxl/native.c b/drivers/misc/cxl/native.c
> index 16948915eb0d..debd97147b58 100644
> --- a/drivers/misc/cxl/native.c
> +++ b/drivers/misc/cxl/native.c
> @@ -182,10 +182,8 @@ static int spa_max_procs(int spa_size)
>  	return ((spa_size / 8) - 96) / 17;
>  }
>  
> -static int alloc_spa(struct cxl_afu *afu)
> +int cxl_alloc_spa(struct cxl_afu *afu)
>  {
> -	u64 spap;
> -
>  	/* Work out how many pages to allocate */
>  	afu->spa_order = 0;
>  	do {
> @@ -204,6 +202,13 @@ static int alloc_spa(struct cxl_afu *afu)
>  	pr_devel("spa pages: %i afu->spa_max_procs: %i   afu->num_procs: %i\n",
>  		 1<<afu->spa_order, afu->spa_max_procs, afu->num_procs);
>  
> +	return 0;
> +}
> +
> +static void attach_spa(struct cxl_afu *afu)
> +{
> +	u64 spap;
> +
>  	afu->sw_command_status = (__be64 *)((char *)afu->spa +
>  					    ((afu->spa_max_procs + 3) * 128));
>  
> @@ -212,13 +217,15 @@ static int alloc_spa(struct cxl_afu *afu)
>  	spap |= CXL_PSL_SPAP_V;
>  	pr_devel("cxl: SPA allocated at 0x%p. Max processes: %i, sw_command_status: 0x%p CXL_PSL_SPAP_An=0x%016llx\n", afu->spa, afu->spa_max_procs, afu->sw_command_status, spap);
>  	cxl_p1n_write(afu, CXL_PSL_SPAP_An, spap);
> -
> -	return 0;
>  }
>  
> -static void release_spa(struct cxl_afu *afu)
> +static inline void detach_spa(struct cxl_afu *afu)
>  {
>  	cxl_p1n_write(afu, CXL_PSL_SPAP_An, 0);
> +}
> +
> +void cxl_release_spa(struct cxl_afu *afu)
> +{
>  	free_pages((unsigned long) afu->spa, afu->spa_order);
>  }
>  
> @@ -446,8 +453,11 @@ static int activate_afu_directed(struct cxl_afu *afu)
>  
>  	dev_info(&afu->dev, "Activating AFU directed mode\n");
>  
> -	if (alloc_spa(afu))
> -		return -ENOMEM;
> +	if (afu->spa == NULL) {
> +		if (cxl_alloc_spa(afu))
> +			return -ENOMEM;
> +	}
> +	attach_spa(afu);
>  
>  	cxl_p1n_write(afu, CXL_PSL_SCNTL_An, CXL_PSL_SCNTL_An_PM_AFU);
>  	cxl_p1n_write(afu, CXL_PSL_AMOR_An, 0xFFFFFFFFFFFFFFFFULL);
> @@ -560,8 +570,6 @@ static int deactivate_afu_directed(struct cxl_afu *afu)
>  	cxl_afu_disable(afu);
>  	cxl_psl_purge(afu);
>  
> -	release_spa(afu);
> -
>  	return 0;
>  }
>  
> diff --git a/drivers/misc/cxl/pci.c b/drivers/misc/cxl/pci.c
> index 32ad09705949..1849c1785b49 100644
> --- a/drivers/misc/cxl/pci.c
> +++ b/drivers/misc/cxl/pci.c
> @@ -551,6 +551,9 @@ static void cxl_release_afu(struct device *dev)
>  
>  	pr_devel("cxl_release_afu\n");
>  
> +	if (afu->spa)
> +		cxl_release_spa(afu);
> +
>  	kfree(afu);
>  }
>  

  reply	other threads:[~2015-08-11  3:42 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-28  5:28 [PATCH v2 00/10] CXL EEH Handling Daniel Axtens
2015-07-28  5:28 ` [PATCH v2 01/10] cxl: Drop commands if the PCI channel is not in normal state Daniel Axtens
2015-08-11  3:31   ` Cyril Bur
2015-08-11  4:11     ` Daniel Axtens
2015-07-28  5:28 ` [PATCH v2 02/10] cxl: Allocate and release the SPA with the AFU Daniel Axtens
2015-08-11  3:42   ` Cyril Bur [this message]
2015-08-11  4:16     ` Daniel Axtens
2015-07-28  5:28 ` [PATCH v2 03/10] cxl: Make IRQ release idempotent Daniel Axtens
2015-08-11  3:44   ` Cyril Bur
2015-07-28  5:28 ` [PATCH v2 04/10] cxl: Clean up adapter MMIO unmap path Daniel Axtens
2015-08-11  3:52   ` Cyril Bur
2015-08-11  6:38     ` Daniel Axtens
2015-07-28  5:28 ` [PATCH v2 05/10] cxl: Refactor adaptor init/teardown Daniel Axtens
2015-08-11  6:01   ` Cyril Bur
2015-08-11 22:38     ` Daniel Axtens
2015-08-12 10:14     ` David Laight
2015-08-12 21:58       ` Daniel Axtens
2015-07-28  5:28 ` [PATCH v2 06/10] cxl: Refactor AFU init/teardown Daniel Axtens
2015-08-11  3:59   ` Cyril Bur
2015-07-28  5:28 ` [PATCH v2 07/10] cxl: Don't remove AFUs/vPHBs in cxl_reset Daniel Axtens
2015-08-11  5:57   ` Cyril Bur
2015-07-28  5:28 ` [PATCH v2 08/10] cxl: Allow the kernel to trust that an image won't change on PERST Daniel Axtens
2015-08-11  7:15   ` Cyril Bur
2015-08-11 11:22     ` Daniel Axtens
2015-08-11 23:47       ` Daniel Axtens
2015-07-28  5:28 ` [PATCH v2 09/10] cxl: EEH support Daniel Axtens
2015-08-11  7:23   ` Cyril Bur
2015-07-28  5:28 ` [PATCH v2 10/10] cxl: Add CONFIG_CXL_EEH symbol Daniel Axtens
2015-08-11  3:59   ` Cyril Bur

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=20150811134254.0358f0e3@camb691 \
    --to=cyrilbur@gmail.com \
    --cc=dja@axtens.net \
    --cc=imunsie@au.ibm.com \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=mikey@neuling.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;
as well as URLs for NNTP newsgroup(s).