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=-5.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 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 4193CC3F2CF for ; Fri, 28 Feb 2020 09:18:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1ABCA246A2 for ; Fri, 28 Feb 2020 09:18:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726490AbgB1JSL (ORCPT ); Fri, 28 Feb 2020 04:18:11 -0500 Received: from mx2.suse.de ([195.135.220.15]:50770 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726005AbgB1JSL (ORCPT ); Fri, 28 Feb 2020 04:18:11 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id EAEE5B37F; Fri, 28 Feb 2020 09:18:09 +0000 (UTC) Subject: Re: [PATCH v7 34/38] sg: protect multiple receivers To: Douglas Gilbert , linux-scsi@vger.kernel.org Cc: martin.petersen@oracle.com, jejb@linux.vnet.ibm.com References: <20200227165902.11861-1-dgilbert@interlog.com> <20200227165902.11861-35-dgilbert@interlog.com> From: Hannes Reinecke Message-ID: <07ed674d-fb4b-12d7-8019-e40cd3fe5655@suse.de> Date: Fri, 28 Feb 2020 10:18:09 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20200227165902.11861-35-dgilbert@interlog.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org On 2/27/20 5:58 PM, Douglas Gilbert wrote: > If two threads call ioctl(SG_IORECEIVE) [or read()] on the same > file descriptor there is a potential race on the same request > response. Use atomic bit operations to make sure only one thread > gets each request response. [The other thread will either get > another request response or nothing.] > > Also make sfp cleanup a bit more robust and report if the > number of submitted requests (which are decremented when > completed) is other than the expected value of zero. > > Signed-off-by: Douglas Gilbert > --- > drivers/scsi/sg.c | 54 +++++++++++++++++++++++++++++++++-------------- > 1 file changed, 38 insertions(+), 16 deletions(-) > Reviewed-by: Hannes Reinecke Cheers, Hannes -- Dr. Hannes Reinecke Teamlead Storage & Networking hare@suse.de +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer