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: 11700049 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 24F6D14DD for ; Tue, 4 Aug 2020 09:07:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 406BB206DA for ; Tue, 4 Aug 2020 09:07:56 +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 S1730076AbgHDJHz (ORCPT ); Tue, 4 Aug 2020 05:07:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729959AbgHDJHz (ORCPT ); Tue, 4 Aug 2020 05:07:55 -0400 Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0957FC06174A for ; Tue, 4 Aug 2020 02:07:55 -0700 (PDT) Received: by mail-qk1-x741.google.com with SMTP id l6so37727893qkc.6 for ; Tue, 04 Aug 2020 02:07:55 -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=Nr+75/Fb5KF8lZfRAaYlCqny1r5ZUuBJMWdUi+g/PcJpkot3ZIEK7Erh+O5jy7xhLV MsJJz8eKeZmOKtVz1VsfwW3iprG07TnSbQ38Difa9y2+PoxcocMPrjlBQRhimxitrYZS zZBL1y05dfAqZ8w55mztNgD7aybdf7F8ja4cLdA9B5V7ajHSOnrQPRJntKSa5lUcuWub D9DJswmKR8RwiZCHQVHx9AIu2RFtmyZYbYGGfz7wIu1ymNNbklJDYgE/K7kFjdYQerpB UpUvL1zC+ZekTB584jsy4Zz/8p6PuM6f238//WcbH7NmxNz55dgInp+LGhyDP1O0MVyx mZPQ== X-Gm-Message-State: AOAM533F7ynhvrXk86Eb74wL8mzzQdLI2L60jjAoi/mTcc+k4KmrJto7 heTaH1J7aXA5xuIp4g0upfVo68IgnT3xOCmGwuVav2xFXv2JG9U73Lfs9kHKPY1a6T3dvdvKuWI c1PDbfbd6in3OImy4402wsPTNuQUFdxbOgUPNa3iEhZiVQioLrJquzuHMjwSwJaM47DzI1wYYgI PPMugwWwg= 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-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@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. */