Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp171005pxv; Thu, 24 Jun 2021 05:31:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGyct1MVijIl5b2E76au5UAnRGkxanp05DCd/GiUhuWG8aeUTviPLGyhqcex5W1X30nLMK X-Received: by 2002:a17:907:9cc:: with SMTP id bx12mr5113961ejc.25.1624537904714; Thu, 24 Jun 2021 05:31:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624537904; cv=none; d=google.com; s=arc-20160816; b=loHYd7Rw4Ht4Aufid1H5Zk4+s2TuYx2E4XWp0CuW8wgBNO5FfH7jQeBOl5vHbcS72j 231sX+MCKE6FVuYJxumsE5pl1ip6pmdcgrixV8VePsESwqfaOQLRgKl1RaWJ2U0+P5Sf oKz4LooWGwNkYI5InQdcXAg3ROneLmKMk+9MlF6WGBqPC+MlbrIYIpgO32QjjlO24RyD sviMCdG2P/dbrAowIu2qi4FKYpyemQIC/MDvluft+He3DTB8ChxrJBsLC5mTe8xxIJdi y9jq2aM2TMidwo1EKXD2eGk6xWNcvN4AxBw8JubsfDm3fyAGzieX/bVrmYYPhHt9XeF4 41VQ== 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=5YkKXF7H3DEAKVxD9KnVmenhtkcfHgrnLQZ1dienrGw=; b=VLQU17ZfrSzzYCpn2AxXg/NIe0AzUX84zLlAMkTGuHmhRr8JRId0dxmbfUG384wqpk VV9z84qSaxrbxiQuXOsrZCzGMYxCAiwfv/CaFccBtOKBrToVY32ePnUZSHK5dtBInpce eN4AvQZ0OX3YS4CC8Ut1jbCcAW3ZbrpNdfC5rvtC5WNchIgIjOZQ435Wb20lQTZMMSmq wYKYlqmy3YWPZjrdyee/Mu6tniwyqwMrr6sjqxH23071mftOoxIkgEOb93n4hxwSdbM6 jxSTzclFJ3pCVhMy5RuxF+ccCEATLa2Wp5PBnKt0D+YrSk++I569+VmZy+cV4qaMdc5p RGCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=POpepCQM; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m9si2946589ejn.683.2021.06.24.05.30.55; Thu, 24 Jun 2021 05:31:44 -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=@kernel.org header.s=k20201202 header.b=POpepCQM; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230136AbhFXMcE (ORCPT + 99 others); Thu, 24 Jun 2021 08:32:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:36612 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229945AbhFXMcC (ORCPT ); Thu, 24 Jun 2021 08:32:02 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F0444613B1; Thu, 24 Jun 2021 12:29:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624537784; bh=TpHGrVK1im57ECcVvQcLPWr9HmYUYU2TSdkASrgq0T4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=POpepCQMVmDJ2xphy1SauemUix0H7pSbQwyvHiVQn+/fKtDIfIA6uhCfep4Tqu4Gx +phmkota/a8HCZ+Hen1FCo3DcJvpXQUdP84sg7aZ0kBj0muBddb6q3ib7Lik8iM4mi blOl9XxebSxhQ6Wbjt8/HY4bsJKO6+uwYiCTGOl7ccQ18drQq35Cv0keWW/+XSGu7i RxmmePozYkB6Wp7fhqmLcp9IoHHMJRxUvyDgEsLJL+8qCHqESX1tdWDwW8ZTw+4DkQ jrC706kDhNJNskyHd1klXtZWMRau5yPrrqregbXK0ANuM72ooyzPZ+q3WGOgAmFlxY N+SdP+yL0bs9g== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1lwOUK-000792-I9; Thu, 24 Jun 2021 14:29:44 +0200 Date: Thu, 24 Jun 2021 14:29:44 +0200 From: Johan Hovold To: Saubhik Mukherjee Cc: Greg KH , jirislaby@kernel.org, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, ldv-project@linuxtesting.org, andrianov@ispras.ru Subject: Re: [PATCH] tty: serial: owl: Fix data race in owl_uart_remove Message-ID: References: <20210617110443.6526-1-saubhik.mukherjee@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 24, 2021 at 05:37:38PM +0530, Saubhik Mukherjee wrote: > On 6/23/21 12:46 PM, Johan Hovold wrote: > > On Wed, Jun 23, 2021 at 11:06:53AM +0530, Saubhik Mukherjee wrote: > >> On 6/17/21 4:52 PM, Greg KH wrote: > >>> On Thu, Jun 17, 2021 at 04:34:43PM +0530, Saubhik Mukherjee wrote: > >>>> Suppose the driver is registered and a UART port is added. Once an > >>>> application opens the port, owl_uart_startup is called which registers > >>>> the interrupt handler owl_uart_irq. > >>>> > >>>> We could have the following race condition: > >>>> > >>>> When device is removed, owl_uart_remove is called, which calls > >>>> uart_remove_one_port, which calls owl_uart_release_port, which writes > >>>> NULL to port->membase. At this point parallely, an interrupt could be > >>>> handled by owl_uart_irq which reads port->membase. > >>>> > >>>> This is because it is possible to remove device without closing a port. > >>>> Thus, we need to check it and call owl_uart_shutdown in owl_uart_remove. > > > > No, this makes no sense at all. The port is deregistered and hung up by > > uart_remove_one_port() (and the interrupt line is consequently disabled > > by the driver) before it is released so this can never happen. > > Thanks for the reply. I am not sure I understand. I could not find any > interrupt disabling in owl_uart_remove. Could you point out where/how is > the interrupt line is disabled before releasing the port? The interrupt line is disabled by owl_uart_shutdown(), which is called when uart_remove_one_port() hangs up an open tty. And as I mentioned this happens after deregistering the port (so no new opens) and before releasing the port. Johan