From patchwork Fri Aug 14 07:41:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Axtens X-Patchwork-Id: 507303 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 72DF11401DE for ; Fri, 14 Aug 2015 17:50:31 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=axtens.net header.i=@axtens.net header.b=qJl6MKlY; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4F5991A2BC8 for ; Fri, 14 Aug 2015 17:50:31 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=axtens.net header.i=@axtens.net header.b=qJl6MKlY; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from ozlabs.org (ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 146B11A1DE9 for ; Fri, 14 Aug 2015 17:44:17 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=axtens.net header.i=@axtens.net header.b=qJl6MKlY; dkim-atps=neutral Received: by ozlabs.org (Postfix) id D695E140293; Fri, 14 Aug 2015 17:44:16 +1000 (AEST) Delivered-To: linuxppc-dev@ozlabs.org Received: from mail-pa0-x22f.google.com (mail-pa0-x22f.google.com [IPv6:2607:f8b0:400e:c03::22f]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 64CD4140291 for ; Fri, 14 Aug 2015 17:44:16 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=axtens.net header.i=@axtens.net header.b=qJl6MKlY; dkim-atps=neutral Received: by paccq16 with SMTP id cq16so11338570pac.1 for ; Fri, 14 Aug 2015 00:44:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=RLtnk3tvM5LNcfl3wVnvGHZ+aHsYKu61fRTRbyIX3b8=; b=qJl6MKlYKxtK9plEUvbEZtnYuj5yE9v2kk+yWABq2zG0Rg5O0XQ98bytTfVdandzh8 9cISg9K3ao9lNrHQooIO6fECYGnFkzouT3ee1LTe4WOFL+Y2gZRJC4ND1ohggTNQTU4V S9gUrJ6+5DzPtKBB3SqV5h9NVoPcmOgfl9Pqw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=RLtnk3tvM5LNcfl3wVnvGHZ+aHsYKu61fRTRbyIX3b8=; b=addrio6yC4F58qJWTBeIOkwDOJiJsNRhSeolWjd6BytWQ70E9NUTvMoRliGXYg6KDP vPlGFFwtl0pcRzNAmRSzesUR1udGp22xOsP7uHWqYtnpAaGhtXoBEgGdT79Mm21moWQZ QjiG5tjdhM9XOcw47BY7/2jQoxSCiKyqVKijoYDUO/uHwAVdBhXeOuZynAbBDE3mje1F lSmtERs/BGEe03kwRuPrvddL/gU26ecGdPhUtSAMtJ94DQZf5pC2wmjzcq+w2z5PImxe 6oXCGwa48yewdFFhqS7qRLHV0+BaD1f/cueX6PIqBQ3V4ZWttymPuo4WCCI+IXqUwVjL OeyA== X-Gm-Message-State: ALoCoQnUeqjPBVEoyU1y8XZ889Sy2vmXWncOsCLl3LDPG1wdeeg90LbyN1mbcK9/xIWBnWA2K7y3 X-Received: by 10.68.65.77 with SMTP id v13mr85750254pbs.157.1439538254759; Fri, 14 Aug 2015 00:44:14 -0700 (PDT) Received: from gamma.au.ibm.com (ppp167-251-139.static.internode.on.net. [59.167.251.139]) by smtp.gmail.com with ESMTPSA id xp10sm5020637pac.34.2015.08.14.00.44.11 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 14 Aug 2015 00:44:14 -0700 (PDT) From: Daniel Axtens To: linuxppc-dev@ozlabs.org Subject: [PATCH v5 03/11] cxl: Allocate and release the SPA with the AFU Date: Fri, 14 Aug 2015 17:41:19 +1000 Message-Id: <1439538087-32137-4-git-send-email-dja@axtens.net> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1439538087-32137-1-git-send-email-dja@axtens.net> References: <1439538087-32137-1-git-send-email-dja@axtens.net> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mikey@neuling.org, Daniel Axtens , imunsie@au.ibm.com MIME-Version: 1.0 Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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) Acked-by: Cyril Bur Signed-off-by: Daniel Axtens Acked-by: Ian Munsie --- drivers/misc/cxl/cxl.h | 3 +++ drivers/misc/cxl/native.c | 33 ++++++++++++++++++++++----------- drivers/misc/cxl/pci.c | 2 ++ 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/drivers/misc/cxl/cxl.h b/drivers/misc/cxl/cxl.h index 9b9e89fd02cc..d540542f9931 100644 --- a/drivers/misc/cxl/cxl.h +++ b/drivers/misc/cxl/cxl.h @@ -632,6 +632,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 44568dd68bb9..b37f2e8004f5 100644 --- a/drivers/misc/cxl/native.c +++ b/drivers/misc/cxl/native.c @@ -183,10 +183,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 { @@ -205,6 +203,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<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)); @@ -213,14 +218,19 @@ 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); - free_pages((unsigned long) afu->spa, afu->spa_order); +} + +void cxl_release_spa(struct cxl_afu *afu) +{ + if (afu->spa) { + free_pages((unsigned long) afu->spa, afu->spa_order); + afu->spa = NULL; + } } int cxl_tlb_slb_invalidate(struct cxl *adapter) @@ -447,8 +457,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); @@ -559,8 +572,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 1d314f1f95fe..dc26cdd653ad 100644 --- a/drivers/misc/cxl/pci.c +++ b/drivers/misc/cxl/pci.c @@ -552,6 +552,8 @@ static void cxl_release_afu(struct device *dev) pr_devel("cxl_release_afu\n"); idr_destroy(&afu->contexts_idr); + cxl_release_spa(afu); + kfree(afu); }