From patchwork Tue Aug 4 02:13:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muneendra Kumar X-Patchwork-Id: 258010 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.6 required=3.0 tests=BAYES_00, DATE_IN_PAST_06_12, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E30DC433DF for ; Tue, 4 Aug 2020 09:07:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3D75E206DA for ; Tue, 4 Aug 2020 09:07:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="VbkiMTHI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730075AbgHDJHy (ORCPT ); Tue, 4 Aug 2020 05:07:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729959AbgHDJHy (ORCPT ); Tue, 4 Aug 2020 05:07:54 -0400 Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FAF6C06174A for ; Tue, 4 Aug 2020 02:07:54 -0700 (PDT) Received: by mail-qk1-x742.google.com with SMTP id q128so5383124qkd.2 for ; Tue, 04 Aug 2020 02:07:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gM9cvLVVvrWgl6gMJCF21PDZgJ5IErhbxfsBmfgw/lA=; b=VbkiMTHI0oNnG7fYUlodrbJT0U/MknuMw4CWr2nQQF4jXzSBPHVCNJLnsgJR8mru5C 7kOnvpP5oiCfOC+eky4k19d7JqDfGWRatIhvpLLoC0f0Key20j7ZR9h15WTzbPsYJ8QT TG2QzavXmMm9Gwv6I1TwHwW52CiJaIk9NTlMQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=gM9cvLVVvrWgl6gMJCF21PDZgJ5IErhbxfsBmfgw/lA=; b=asDUQqyDhuRwVDtGr5XEgD3GoUvLzEUFAnN9gwh5n6VWmqo5i18/kBbL7oH8uPY+XZ 2iFO1TplhhSTtic+TPnbiThWyW/7Hfs9L0jn6CPA7tz/WR7bmENOF8pgrhUSQ1mEi6Cb TPXSqISILvsMpttiMx/HiODSU69Fn3E17ZIOisXIfpxUgMPWeUH6GCjC+L2qZcZG+VqB XQCPihgK3QDUmdXzZtObd7OZ644eDQqEW+sf4uPOBgxUKujHDpcYasqVj2rFyl5nMDUp Ws1P4PdNfZDgc2saNLfGqKfPP85K9T8bwtwtUXfP9MB0oYcaXud1brPHwuhMC64MOqhe UR/g== X-Gm-Message-State: AOAM532V2Tkxnl7jqjk+WbwsGwtYu1EKr/RXQ41V3zlKbFpd3HktGyod L+xH4vt8JE/s8zbkAMlutS6mdnJpG10= X-Google-Smtp-Source: ABdhPJyxPO62x+Xfuz7B7G5OsijtIqAC5jJ3H8U7BOKdxaViIpWg/Yr4PtWcXKEjgQXADixcxG43rg== X-Received: by 2002:a05:620a:1525:: with SMTP id n5mr5297979qkk.126.1596532073470; Tue, 04 Aug 2020 02:07:53 -0700 (PDT) Received: from localhost.localdomain ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id 65sm19989407qkn.103.2020.08.04.02.07.50 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Aug 2020 02:07:52 -0700 (PDT) From: Muneendra To: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org Cc: pbonzini@redhat.com, emilne@redhat.com, mkumar@redhat.com, Gaurav Srivastava , James Smart , Muneendra Subject: [RFC 14/16] lpfc: vmid: Timeout implementation for vmid Date: Tue, 4 Aug 2020 07:43:14 +0530 Message-Id: <1596507196-27417-15-git-send-email-muneendra.kumar@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1596507196-27417-1-git-send-email-muneendra.kumar@broadcom.com> References: <1596507196-27417-1-git-send-email-muneendra.kumar@broadcom.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Gaurav Srivastava This patch implements the timeout functionality for the vmid. After the set time period of inactivity, the vmid is deregistered from the switch. Signed-off-by: Gaurav Srivastava Signed-off-by: James Smart Signed-off-by: Muneendra --- drivers/scsi/lpfc/lpfc_hbadisc.c | 109 +++++++++++++++++++++++++++++++ drivers/scsi/lpfc/lpfc_init.c | 40 ++++++++++++ 2 files changed, 149 insertions(+) diff --git a/drivers/scsi/lpfc/lpfc_hbadisc.c b/drivers/scsi/lpfc/lpfc_hbadisc.c index 142a02114479..b20013866942 100644 --- a/drivers/scsi/lpfc/lpfc_hbadisc.c +++ b/drivers/scsi/lpfc/lpfc_hbadisc.c @@ -190,6 +190,115 @@ lpfc_dev_loss_tmo_callbk(struct fc_rport *rport) return; } +/** + * lpfc_check_inactive_vmid_one - VMID inactivity checker for a vport + * @vport: Pointer to vport context object. + * + * This function checks for idle vmid entries related to a particular vport. If + * found unused/idle, it frees them accordingly. + **/ +static void lpfc_check_inactive_vmid_one(struct lpfc_vport *vport) +{ + u16 i, keep; + u32 difftime = 0, r; + u64 *lta; + int cpu; + + write_lock(&vport->vmid_lock); + + if (!vport->cur_vmid_cnt) + goto out; + + /* iterate through the table */ + for (i = 0; i < LPFC_VMID_HASH_SIZE; ++i) { + if (vport->hash_table[i] && (vport->hash_table[i]->flag & + LPFC_VMID_REGISTERED)) { + /* check if the particular vmid is in use */ + /* for all available per cpu variable */ + for_each_possible_cpu(cpu) { + /* if last access time is less than timeout */ + lta = per_cpu_ptr( + vport->hash_table[i]->last_io_time, + cpu); + if (!lta) + continue; + difftime = (jiffies) - (*lta); + if ((vport->vmid_inactivity_timeout * + JIFFIES_PER_HR) > difftime) { + keep = 1; + break; + } + } + + /* if none of the cpus have been used by the vm, */ + /* remove the entry if already registered */ + if (!keep) { + /* mark the entry for deregistration */ + vport->hash_table[i]->flag = + LPFC_VMID_DE_REGISTER; + write_unlock(&vport->vmid_lock); + if (vport->vmid_priority_tagging) + r = lpfc_vmid_uvem(vport, + vport->hash_table[i], + false); + else + r = lpfc_vmid_cmd(vport, + SLI_CTAS_DAPP_IDENT, + vport->hash_table[i]); + + /* decrement number of active vms and mark */ + /* entry in slot as free */ + write_lock(&vport->vmid_lock); + if (!r) { + struct lpfc_vmid *ht = + vport->hash_table[i]; + vport->cur_vmid_cnt--; + ht->flag = LPFC_VMID_SLOT_FREE; + free_percpu(ht->last_io_time); + ht->last_io_time = NULL; + vport->hash_table[i] = NULL; + } + } + } + keep = 0; + } + out: + write_unlock(&vport->vmid_lock); +} + +/** + * lpfc_check_inactive_vmid - VMID inactivity checker + * @phba: Pointer to hba context object. + * + * This function is called from the worker thread to determine if an entry in + * the vmid table can be released since there was no IO activity seen from that + * particular VM for the specified time. When this happens, the entry in the + * table is released and also the resources on the switch cleared. + **/ + +void lpfc_check_inactive_vmid(struct lpfc_hba *phba) +{ + struct lpfc_vport *vport; + struct lpfc_vport **vports; + int i; + + vports = lpfc_create_vport_work_array(phba); + if (!vports) + return; + + for (i = 0; i <= phba->max_vports; i++) { + if ((!vports[i]) && (i == 0)) + vport = phba->pport; + else + vport = vports[i]; + if (!vport) + break; + + lpfc_check_inactive_vmid_one(vport); + } + lpfc_destroy_vport_work_array(phba, vports); +} + /** * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler * @ndlp: Pointer to remote node object. diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c index 419d7372e5c5..6e59744f994f 100644 --- a/drivers/scsi/lpfc/lpfc_init.c +++ b/drivers/scsi/lpfc/lpfc_init.c @@ -4822,6 +4822,42 @@ lpfc_sli4_fcf_redisc_wait_tmo(struct timer_list *t) lpfc_worker_wake_up(phba); } +/** + * lpfc_vmid_poll - VMID timeout detection + * @ptr: Map to lpfc_hba data structure pointer. + * + * This routine is invoked when there is no IO on by a VM for the specified + * amount of time. When this situation is detected, the VMID has to be + * deregistered from the switch and all the local resources freed. The VMID + * will be reassigned to the VM once the IO begins. + **/ +static void +lpfc_vmid_poll(struct timer_list *t) +{ + struct lpfc_hba *phba = from_timer(phba, t, inactive_vmid_poll); + u32 wake_up = 0; + + /* check if there is a need to issue QFPA */ + if (phba->pport->vmid_priority_tagging) { + wake_up = 1; + phba->pport->work_port_events |= WORKER_CHECK_VMID_ISSUE_QFPA; + } + + /* Is the vmid inactivity timer enabled */ + if (phba->pport->vmid_inactivity_timeout || + phba->pport->load_flag & FC_DEREGISTER_ALL_APP_ID) { + wake_up = 1; + phba->pport->work_port_events |= WORKER_CHECK_INACTIVE_VMID; + } + + if (wake_up) + lpfc_worker_wake_up(phba); + + /* restart the timer for the next iteration */ + mod_timer(&phba->inactive_vmid_poll, jiffies + msecs_to_jiffies(1000 * + LPFC_VMID_TIMER)); +} + /** * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code * @phba: pointer to lpfc hba data structure. @@ -6669,6 +6705,10 @@ lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba) phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc; phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free; + /* for VMID idle timeout if VMID is enabled */ + if (lpfc_is_vmid_enabled(phba)) + timer_setup(&phba->inactive_vmid_poll, lpfc_vmid_poll, 0); + /* * Initialize the SLI Layer to run with lpfc SLI4 HBAs. */