Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp631868ybt; Wed, 17 Jun 2020 09:50:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLRMsZLbcliCZ/OWHG49W1xt6SNC1IdhPV5U+Er5OfwB6a0+EOmiV7+xXJdn4W1b2s38No X-Received: by 2002:a50:f145:: with SMTP id z5mr126404edl.78.1592412643485; Wed, 17 Jun 2020 09:50:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592412643; cv=none; d=google.com; s=arc-20160816; b=K0IUvKqmS1CkZ4BRawXDZeD2of/rMTkpp5rhlP8wZDdfYpKrHnoyWj+GLfwoXtaJj/ PTJgveLU0fb75HLzXMkIDD5+wq5cMF+rwUHPeGterQp0eNsYt7tlPdZbs/M+RuVut12F V3+zFzebLzI3pk9o2D/jwR8t59Zkl74iVofRyeGhQo2V/YbwZySgV72p7V+brSKuQjhU 6dkAUuoUO24MJCVQSqo2YSiPBtSwHsiDyeQVTp2w5/qKDz988EjppaaCOpcVHq3qhnup bfuZlg8tikWjshtPcPmQraWHfbgNV97YUmB1uk/PPi07Xrb0jInhIa2rttvJU0NnjYat 60JA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=iaQWLjI5fwfFGmLCckr/wYP6bEsy7u4WBriUtSeoAnM=; b=0zo+tRtUz4vTw99kbYj2EuoWOBphaPfx6XBuub08bDWa8RE9L5UubE1VXYET2bPeYg pumm0K62xunSsPII2hJk3g3W46+T1o+KGB+CwB3hJ86VMvgSAwKQIV4NSDGEJce3/SWl 85cukSpAdrcsNQCfo6VCHOtkId3wSg7MEFYMkL33oWlDLUjC72iN8NzoEk/fRlvVR7dM 7FU8huSW1/f5EgF7GaKSdcPLvTlQ+MyAvfJ2W/yOyBN2wcSOhSDAyovAojNjMKMc05l9 izlBAIvF7HkVIgv2dz1y8OwMPariakC8X0OO6rZtPeih+jzmICYlGzG6iBHgi2ahTNac 1FTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=OkfzEmkB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ot10si245495ejb.319.2020.06.17.09.50.20; Wed, 17 Jun 2020 09:50:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=OkfzEmkB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727052AbgFQQsO (ORCPT + 99 others); Wed, 17 Jun 2020 12:48:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727033AbgFQQsF (ORCPT ); Wed, 17 Jun 2020 12:48:05 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 684F9C06174E; Wed, 17 Jun 2020 09:48:05 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id l17so2524053wmj.0; Wed, 17 Jun 2020 09:48:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iaQWLjI5fwfFGmLCckr/wYP6bEsy7u4WBriUtSeoAnM=; b=OkfzEmkBHCTsEkJzVex/aFcLll3H8vT+4nF+tYkC5s+bbr3MntTdGpx0O5K+8L8h/h bwj7CwiFBq/bagZLqrHRHm7gY6fAX2RYRfdolTkSCQB+qOS6Mx9yEVhfml/Ei5iaTpOt Q0w37kyIjLX5REjbUljOO0yPaDLqxH4Dwy7LE79DN6cSrPPohBbt7XA302U8BsthoFif t7ZyQKjfdJ1QBrYOvi76LQF22LZHL9WfOJ+n1vCRPDNx9l63b8HsLALKoZ/Y2s3mD02l owml6Y4mjKRBQfBzkw820AJEq7RbEM8X8CVhCTFAwsFkAHMTw3TFiT5ZOnAtUuWmJqGj NLSQ== 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:mime-version:content-transfer-encoding; bh=iaQWLjI5fwfFGmLCckr/wYP6bEsy7u4WBriUtSeoAnM=; b=b7jJzqz/k42Nc1ZLx+PNJmahTbjeIxCfNkMyIJLfq4S0mxa6LvxiVFiQY/DTK3h7k8 KTwTZQimCMvb5iy64KNUSSNf5621yFDRvnuLIWIiYd1Bshaewu9oVy29qgXFvrA5nIPg 5NIyfXpdlhqT2dTn5/BdkaadyccsjECgbnY3WJFyM8TyviCwxmB/xtL8tHNDVLOPMmAw hheL/QZXWa8y2WTc1QlM2/ISjoREbVelC+We4F48Hi/td+3S+55OL6zfiaAtkyP8DFrl U73xY7km/HOxKPVkr3U1THhKQU5GcIXmhyHot7W9eVMGosTFtEXcQesOlmNMbzJgC7Fq ew9w== X-Gm-Message-State: AOAM5328s1SGyoFAgAEfRatvHkhCMZj8t1Fzr4uzERar6WX8pdlkpKb0 2SkHmAvojYtIpk5C2LcIIEoAvV29QzxAJg== X-Received: by 2002:a1c:1946:: with SMTP id 67mr964176wmz.59.1592412483964; Wed, 17 Jun 2020 09:48:03 -0700 (PDT) Received: from localhost.localdomain (ip-213-220-210-175.net.upcbroadband.cz. [213.220.210.175]) by smtp.gmail.com with ESMTPSA id g3sm199165wrb.46.2020.06.17.09.48.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jun 2020 09:48:03 -0700 (PDT) From: "Andrea Parri (Microsoft)" To: "K . Y . Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Michael Kelley Cc: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, "Andrea Parri (Microsoft)" Subject: [PATCH 7/8] scsi: storvsc: Introduce the per-storvsc_device spinlock Date: Wed, 17 Jun 2020 18:46:41 +0200 Message-Id: <20200617164642.37393-8-parri.andrea@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200617164642.37393-1-parri.andrea@gmail.com> References: <20200617164642.37393-1-parri.andrea@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org storvsc uses the spinlock of the hv_device's primary channel to serialize modifications of stor_chns[] performed by storvsc_do_io() and storvsc_change_target_cpu(), when it could/should use a (per-) storvsc_device spinlock: this change untangles the synchronization mechanism for the (storvsc-specific) stor_chns[] array from the "generic" VMBus code and data structures, clarifying the scope of this synchronization mechanism. Signed-off-by: Andrea Parri (Microsoft) --- drivers/scsi/storvsc_drv.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c index 072ed87286578..8ff21e69a8be8 100644 --- a/drivers/scsi/storvsc_drv.c +++ b/drivers/scsi/storvsc_drv.c @@ -462,6 +462,11 @@ struct storvsc_device { * Mask of CPUs bound to subchannels. */ struct cpumask alloced_cpus; + /* + * Serializes modifications of stor_chns[] from storvsc_do_io() + * and storvsc_change_target_cpu(). + */ + spinlock_t lock; /* Used for vsc/vsp channel reset process */ struct storvsc_cmd_request init_request; struct storvsc_cmd_request reset_request; @@ -639,7 +644,7 @@ static void storvsc_change_target_cpu(struct vmbus_channel *channel, u32 old, return; /* See storvsc_do_io() -> get_og_chn(). */ - spin_lock_irqsave(&device->channel->lock, flags); + spin_lock_irqsave(&stor_device->lock, flags); /* * Determines if the storvsc device has other channels assigned to @@ -676,7 +681,7 @@ static void storvsc_change_target_cpu(struct vmbus_channel *channel, u32 old, WRITE_ONCE(stor_device->stor_chns[new], channel); cpumask_set_cpu(new, &stor_device->alloced_cpus); - spin_unlock_irqrestore(&device->channel->lock, flags); + spin_unlock_irqrestore(&stor_device->lock, flags); } static void handle_sc_creation(struct vmbus_channel *new_sc) @@ -1433,14 +1438,14 @@ static int storvsc_do_io(struct hv_device *device, } } } else { - spin_lock_irqsave(&device->channel->lock, flags); + spin_lock_irqsave(&stor_device->lock, flags); outgoing_channel = stor_device->stor_chns[q_num]; if (outgoing_channel != NULL) { - spin_unlock_irqrestore(&device->channel->lock, flags); + spin_unlock_irqrestore(&stor_device->lock, flags); goto found_channel; } outgoing_channel = get_og_chn(stor_device, q_num); - spin_unlock_irqrestore(&device->channel->lock, flags); + spin_unlock_irqrestore(&stor_device->lock, flags); } found_channel: @@ -1881,6 +1886,7 @@ static int storvsc_probe(struct hv_device *device, init_waitqueue_head(&stor_device->waiting_to_drain); stor_device->device = device; stor_device->host = host; + spin_lock_init(&stor_device->lock); hv_set_drvdata(device, stor_device); stor_device->port_number = host->host_no; -- 2.25.1