Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp12967836rwl; Wed, 4 Jan 2023 01:19:24 -0800 (PST) X-Google-Smtp-Source: AMrXdXsIy3TRQkI57RLM16nD95js0H6zirhtxXvdQpIZzY89hU3glZ9VGxJPNV/5qcwunfOvQOpe X-Received: by 2002:a17:902:d68b:b0:192:ef8e:4258 with SMTP id v11-20020a170902d68b00b00192ef8e4258mr1115223ply.14.1672823963936; Wed, 04 Jan 2023 01:19:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672823963; cv=none; d=google.com; s=arc-20160816; b=chvmgvDsncbEEREcr+5WU+sYBqdHvfzdcpy7Xfs2ChrNaH0ZfW6G0YzzN9iafSLmHs cds/oG6349rELTFROKgvaQii9lGlqfdhoBUDKQolkB0W9Lo4auNpmzZe3nXBPKOLEFYZ 4khnpEPG3lnP4yxYjspLh86hB95RaT6Zv+VyvEWoGLPaGQ4PcPAYoQlXDkKMmu0/WbkA 2x6++9Il3I35L4Khp1KOhwzKUf6jqDrGJsrcefukg2Hg4lsOdr2nYElGnJg1izGHgscG aqNYh7hExpAB0BN5KAnQS1y3BJ5f37MQvUv2GgPVkSvbhOQKMGGCsOpgXVqKC6XqpOEq hCVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=4yGWrXHii8kKJwv1S+3nfVEtyNBmKsm3gS1Xsf3WyVA=; b=yHieTf1wGHiIXVJ1JeSgNrbgoJ4IeWkpdex5t+9UmbzjHl9v8BQJko4g9A67us/6po R7JNmCpACB+vd1unrndKDcDuPK8dWBY11e1vpXvUtqjZG80V6if49JoNKOHFKAzB8USH CsZnXymTdml3/8C2dnQVGBxRrHiQJyRRme247Vwc1zWKmby/uj1vsd1wuKNjUx6xCTYg 5R96PM5vydDS3wNFIpDmPZwAKGxzKUvEc3rw2FfWNYTQ7R30nvwH404IKU7TQj49Ymxh vZklQVItukV0FHS/v8yLui6VCYldKD7bL/gWL5ZWTS6Ikb3GcBs3Pm7978ckpu+9rdeP dATA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mailo.com header.s=mailo header.b=D26SDwqE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailo.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f6-20020a170902ce8600b0018938988ea9si39238371plg.520.2023.01.04.01.19.16; Wed, 04 Jan 2023 01:19:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@mailo.com header.s=mailo header.b=D26SDwqE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234567AbjADJAL (ORCPT + 57 others); Wed, 4 Jan 2023 04:00:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238646AbjADI7u (ORCPT ); Wed, 4 Jan 2023 03:59:50 -0500 Received: from msg-4.mailo.com (msg-4.mailo.com [213.182.54.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3324B222; Wed, 4 Jan 2023 00:59:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailo.com; s=mailo; t=1672822777; bh=MI19Bt6j5+vEb0xMTmFMufyPhjb/G2VdVdfSJyngXD4=; h=X-EA-Auth:Date:From:To:Cc:Subject:Message-ID:References: MIME-Version:Content-Type:In-Reply-To; b=D26SDwqEZYm04/bd7F7nTISPscO8ULSmnLTq+oeBqdx25JKeKRDQIMNIC379hjrIT v5eDcg5AL6MP0grpr5R4oY0uX01fvTPpSV+zr6333naHzMbYupbBIhMthVU4V9QRS+ 5M6r2Ega5TMYW4PCCcHIf1qJ/+Lhkbl0IYUj1yZU= Received: by b-5.in.mailobj.net [192.168.90.15] with ESMTP via ip-206.mailobj.net [213.182.55.206] Wed, 4 Jan 2023 09:59:37 +0100 (CET) X-EA-Auth: 3dYqcVzlZK1WvubetNrJWt8ppfWde/HMNvQ0EK01li/n4JhPYD5rf0RiytvtHMVkS3hYJaukvBTjexSuWZHOcVytsiYiLNcD Date: Wed, 4 Jan 2023 14:29:31 +0530 From: Deepak R Varma To: Greg Kroah-Hartman Cc: Jiri Slaby , "Maciej W. Rozycki" , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Saurabh Singh Sengar , Praveen Kumar , Deepak R Varma Subject: Re: [PATCH v4 1/2] tty: serial: dz: convert atomic_* to refcount_* APIs for map_guard Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 04, 2023 at 09:28:13AM +0100, Greg Kroah-Hartman wrote: > On Tue, Jan 03, 2023 at 03:35:15PM +0530, Deepak R Varma wrote: > > > > - printk(KERN_ERR > > > > - "dz: Unable to reserve MMIO resource\n"); > > > > + refcount_inc(&mux->map_guard); > > > > + if (refcount_read(&mux->map_guard) == 1) { > > > > > > This is now racy, right? > > > > Hello Jiri, > > Thank you for the feedback. You are correct. I have split a single instruction > > in two (or more?) instructions potentially resulting in race conditions. I > > looked through the refcount_* APIs but did not find a direct match. > > > > > > Can you please comment if the the following variation will avoid race condition? > > > > if (!refcount_add_not_zero(1, &mux->map_guard)) { > > refcount_inc(&mux->map_guard); > > ... > > } > > What do you think? The onus is on you to prove the conversion is > correct, otherwise, why do the conversion at all? Hello Greg, Okay. Sounds good. I think the revised approach should be safer. I will work on finding a means to prove that. > > Actually, why do this at all, what is the goal here? And how was this > tested? The objective here is to migrate to specific and improved APIs that are already proved to be better for different reasons as mentioned in the patch log messages. This is as per the Linux Kernel documentation. In terms of testing, First, I did a compile and build test of the changes. I also wrote separate small dummy modules and tested the API transformation. However, these modules were standalone and limited in complexity and intensity. I will try to make these more intense, multithreaded and run the test again. Thank you as always :) ./drv > > thanks, > > greg k-h