Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932433AbbBDHnp (ORCPT ); Wed, 4 Feb 2015 02:43:45 -0500 Received: from mail-bl2on0130.outbound.protection.outlook.com ([65.55.169.130]:23622 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932318AbbBDHno convert rfc822-to-8bit (ORCPT ); Wed, 4 Feb 2015 02:43:44 -0500 From: Dexuan Cui To: Vitaly Kuznetsov , KY Srinivasan , "devel@linuxdriverproject.org" CC: Haiyang Zhang , "linux-kernel@vger.kernel.org" , Jason Wang Subject: RE: [PATCH 3/4] Drivers: hv: vmbus: protect vmbus_get_outgoing_channel() against channel removal Thread-Topic: [PATCH 3/4] Drivers: hv: vmbus: protect vmbus_get_outgoing_channel() against channel removal Thread-Index: AQHQP9L8Y1+ZgKL+o0KoBNVUev3hIZzgFSZw Date: Wed, 4 Feb 2015 07:27:30 +0000 Message-ID: References: <1422982839-3948-1-git-send-email-vkuznets@redhat.com> <1422982839-3948-4-git-send-email-vkuznets@redhat.com> In-Reply-To: <1422982839-3948-4-git-send-email-vkuznets@redhat.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [141.251.55.69] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-EOPAttributedMessage: 0 Authentication-Results: spf=pass (sender IP is 206.191.230.4) smtp.mailfrom=decui@microsoft.com; linuxdriverproject.org; dkim=none (message not signed) header.d=none; X-Forefront-Antispam-Report: CIP:206.191.230.4;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10019020)(6009001)(438002)(164054003)(13464003)(51704005)(377454003)(22756005)(92566002)(47776003)(23726002)(1511001)(66066001)(50466002)(76176999)(2421001)(104016003)(54356999)(77156002)(62966003)(50986999)(102836002)(87936001)(6806004)(86146001)(19580405001)(2656002)(106466001)(33656002)(86362001)(575784001)(97756001)(22746005)(55846006)(106116001)(2920100001)(2950100001)(2900100001)(46406003)(19580395003)(86612001)(2501002)(46102003)(79686002);DIR:OUT;SFP:1102;SCL:1;SRVR:CY1PR0301MB0842;H:064-smtp-out.microsoft.com;FPR:;SPF:Pass;MLV:sfv;LANG:en; X-Microsoft-Antispam: UriScan:;UriScan:; X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;SRVR:CY1PR0301MB0842; X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004);SRVR:CY1PR0301MB0842; X-Forefront-PRVS: 04772EA191 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:;SRVR:CY1PR0301MB0842; X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Feb 2015 07:27:54.7719 (UTC) X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=72f988bf-86f1-41af-91ab-2d7cd011db47;Ip=[206.191.230.4] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR0301MB0842 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;SRVR:CY1PR0301MB0873; X-OriginatorOrg: microsoft.onmicrosoft.com Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3116 Lines: 90 > -----Original Message----- > From: Vitaly Kuznetsov [mailto:vkuznets@redhat.com] > Sent: Wednesday, February 4, 2015 1:01 AM > To: KY Srinivasan; devel@linuxdriverproject.org > Cc: Haiyang Zhang; linux-kernel@vger.kernel.org; Dexuan Cui; Jason Wang > Subject: [PATCH 3/4] Drivers: hv: vmbus: protect vmbus_get_outgoing_channel() > against channel removal > > list_for_each_safe() we have in vmbus_get_outgoing_channel() works, however, > we > are not protected against the channel being removed (e.g. after receiving > rescind > offer). Users of this function (storvsc_do_io() is the only one at this moment) > can get a link to an already freed channel. Make vmbus_get_outgoing_channel() > search holding primary->lock as child channels are not being freed unless they're > removed from parent's list. > > Signed-off-by: Vitaly Kuznetsov > --- > drivers/hv/channel_mgmt.c | 10 +++++++--- > drivers/scsi/storvsc_drv.c | 2 ++ > 2 files changed, 9 insertions(+), 3 deletions(-) > > diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c > index fdccd16..af6243c 100644 > --- a/drivers/hv/channel_mgmt.c > +++ b/drivers/hv/channel_mgmt.c > @@ -881,18 +881,20 @@ cleanup: > */ > struct vmbus_channel *vmbus_get_outgoing_channel(struct vmbus_channel > *primary) > { > - struct list_head *cur, *tmp; > + struct list_head *cur; > int cur_cpu; > struct vmbus_channel *cur_channel; > struct vmbus_channel *outgoing_channel = primary; > int cpu_distance, new_cpu_distance; > + unsigned long flags; > > if (list_empty(&primary->sc_list)) > - return outgoing_channel; > + return vmbus_get_channel(outgoing_channel); > > cur_cpu = hv_context.vp_index[get_cpu()]; > put_cpu(); > - list_for_each_safe(cur, tmp, &primary->sc_list) { > + spin_lock_irqsave(&primary->lock, flags); hmm, we should avoid the locking here because it's a performance killer... How about adding vmbus_get/put_channel() in vmbus_open/close()? Thanks, -- Dexuan > + list_for_each(cur, &primary->sc_list) { > cur_channel = list_entry(cur, struct vmbus_channel, sc_list); > if (cur_channel->state != CHANNEL_OPENED_STATE) > continue; > @@ -913,6 +915,8 @@ struct vmbus_channel > *vmbus_get_outgoing_channel(struct vmbus_channel *primary) > > outgoing_channel = cur_channel; > } > + outgoing_channel = vmbus_get_channel(outgoing_channel); > + spin_unlock_irqrestore(&primary->lock, flags); > > return outgoing_channel; > } > diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c > index 4cff0dd..3b9b851 100644 > --- a/drivers/scsi/storvsc_drv.c > +++ b/drivers/scsi/storvsc_drv.c > @@ -1370,6 +1370,8 @@ static int storvsc_do_io(struct hv_device *device, > > VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); > } > > + vmbus_put_channel(outgoing_channel); > + > if (ret != 0) > return ret; > > -- > 1.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/