Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp346004pxf; Thu, 18 Mar 2021 01:30:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw8s+4SrNN08zd0kNof0guFYommHeS6pKad5dy9EquSnTC5MV6umq0n2XqHhXJSTYtwKbK1 X-Received: by 2002:a05:6402:168c:: with SMTP id a12mr2215635edv.344.1616056212629; Thu, 18 Mar 2021 01:30:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616056212; cv=none; d=google.com; s=arc-20160816; b=CNWonOWy3bu1dDdx3P6y7tI4X3EwpMVIdZLr42+0SXkzcYZvfQ7qGo5adWdaoTkA2q V573z+LZxU/u3/++UeubQ62qROJrl7tPDky1Yf5azhbrloTnM2+rj/cbKJ3/Qdbla1bH XYAXv2clBcQUpbUMYM7YWJcP5QzmjcCeX35ZsAp89Cd9EZRa8ObmmXq2WaBCkEGmeK4k yr3fcEPeZ1sB11Ds9+lF4YknZXdga8kvAaSd1P8gNvz9FMtPKwWT+FZuZvcpFTY6qJrn 6vS4wYxfM3+HII3LUNM83tSJqJDUKS1VCJuq2SKS5gB1Yd7621FV6kgR4i7xDeq9FS47 c7eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=VmrilBreQl5UmH0ExfncaHTK/Gb5Bvy4on9E6V3VT7o=; b=PoKPwkVWda3ktZxnjwp3hqZhWZ6Ko/1Ej4DycSZlHpaOh5Zv0JHInqNuzFp+2M4bL5 rJOEP5nSHgib8N/FX/xxmJGZSfF9Rv5/cNRxIctYLlLm8jCrr8qGLAi5u0mg62CCZ0FW tVysNIXQejH6ihwHjBapO8rtOWpj66fDUrvrXRXgFzeIrlFFaCt6v6H+ylQuWjI5EStw FoywlwVhFMPKe0cgne28z9psfGVeAnWRkgY3R23f1U2kkNYjJUepV5KQvhC/+m8pr5Z1 oPNGqw/AvQNhTyWen8gSemORuBKm31dPQ3YwaZ4d59fi9syOaF+klaoSmFUfKFEJn049 l5dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@metafoo.de header.s=default2002 header.b=TCYBejkY; 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=metafoo.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p10si1050185edm.261.2021.03.18.01.29.48; Thu, 18 Mar 2021 01:30:12 -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=@metafoo.de header.s=default2002 header.b=TCYBejkY; 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=metafoo.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229802AbhCRI2M (ORCPT + 99 others); Thu, 18 Mar 2021 04:28:12 -0400 Received: from www381.your-server.de ([78.46.137.84]:43360 "EHLO www381.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229698AbhCRI15 (ORCPT ); Thu, 18 Mar 2021 04:27:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=metafoo.de; s=default2002; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID; bh=VmrilBreQl5UmH0ExfncaHTK/Gb5Bvy4on9E6V3VT7o=; b=TCYBejkYAm/92Y1mpXgA1yb4VK F4pnir3RZy66aEoBO/WQzGPkQz5SlH98y/ucDjALSRphfZH7r5N6I6XQ/9nTglzY/FxJzifmab1en lSgVUDr91d38kCSYkXyMBbhXWPS7EnbBJZothMeNuKkhT6wCZSivhgGpxO0C76TpXpHxHMUtmjDZR MBly3/hN5tYveYQILGDYKWctvoUIlApG3eh5aOBRChmAqvR0ZV60krBlayLnmv8GWsHgNa3kk4PHL aqZRBR7owH+Iajoo9xCayWSF1NzpMx9n4EvWIHs8owWD8OoEFyDlSL+WQfLMM+ipfYkKhOw9U8QQO 7ENTe6hQ==; Received: from sslproxy01.your-server.de ([78.46.139.224]) by www381.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92.3) (envelope-from ) id 1lMo0W-0004Rh-GN; Thu, 18 Mar 2021 09:27:52 +0100 Received: from [2001:a61:2aa9:e001:9e5c:8eff:fe01:8578] by sslproxy01.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lMo0W-000IxX-Am; Thu, 18 Mar 2021 09:27:52 +0100 Subject: Re: A potential data race in drivers/iio/adc/berlin2-adc.ko To: Pavel Andrianov , Jonathan Cameron Cc: ldv-project@linuxtesting.org, Peter Meerwald-Stadler , Alexandru Ardelean , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org References: From: Lars-Peter Clausen Message-ID: Date: Thu, 18 Mar 2021 09:27:52 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Authenticated-Sender: lars@metafoo.de X-Virus-Scanned: Clear (ClamAV 0.102.4/26111/Wed Mar 17 12:08:39 2021) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/18/21 9:07 AM, Pavel Andrianov wrote: > Hi, > > berlin2_adc_probe [1] registers two interrupt handlers: > berlin2_adc_irq [2] > and berlin2_adc_tsen_irq [3]. The interrupt handlers operate with the > same data, for example, modify > priv->data with different masks: > > priv->data &= BERLIN2_SM_ADC_MASK; > and > priv->data &= BERLIN2_SM_TSEN_MASK; > > If the two interrupt handlers are executed simultaneously, a potential > data race takes place. So, the question is if the situation is > possible. For example, in the case of the handlers are executed on > different CPU cores. > > Best regards, > Pavel > > [1] > https://elixir.bootlin.com/linux/latest/source/drivers/iio/adc/berlin2-adc.c#L283 > > [2] > https://elixir.bootlin.com/linux/latest/source/drivers/iio/adc/berlin2-adc.c#L239 > > [3] > https://elixir.bootlin.com/linux/latest/source/drivers/iio/adc/berlin2-adc.c#L259 > Looking at the code there are two functions. berlin2_adc_tsen_read() and berlin2_adc_read(). These two function are take the same mutex and can not run concurrently. At the beginning of the protected section the corresponding interrupt for that function is enabled and at the end disabled. So at least if the hardware works correctly those two interrupts will never fire at the same time. Now, if the hardware misbehaves the two interrupts could still fire at the same time. - Lars