Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp2377838ybd; Thu, 27 Jun 2019 11:18:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqw/u7aiKYicI5sVduGD0rM6Hd1RrXUiRqwaVkr5l58XP/XJVJCy6nxuFIEcIRGFCFhQiRTH X-Received: by 2002:a17:90a:3688:: with SMTP id t8mr7391518pjb.35.1561659508992; Thu, 27 Jun 2019 11:18:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561659508; cv=none; d=google.com; s=arc-20160816; b=Pf/6UZ5/QHdBJtxS3HrzGA05ZDWXvsBMrFV9wK2/p7OOYrCQ1c5hYkMLbXSQ2V0XgJ V9Xp2EjLKrbxU4K6l3U9PKvE5MUOc84PmCnaimD//LikPARCdWlhAaj7Os45Ec1A6WTV y1hUokgfXNb7Jah8HvvMR0tLRxtEZ6bOzs0oATwBVw5E8L2bMlX/Rp/th9RFP2NWHh54 tid+nmx8Q1yn+gLsuzg5SRkQXwFA9SqCn1NRgURJd9nHGwJD+xAChesUjxfP0roBKoCG yx3YtFgbtS3bYzdx2HzYWAM7lU3FFY3ER2sHlhB77tN7xsj5zKKzl1eJARVFbNs+sMPi a7cA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:user-agent:cc:subject :from:to:references:in-reply-to:content-transfer-encoding :mime-version:dkim-signature; bh=Bpofm98JR2l7lcPJ969N4VZoEODQ4tMNvSqIeizQCUo=; b=ja4HHfldwK+gEf1J8rEmxJ8O5bY12B4pgk0lfeJN4tCAp2kVxOhMFd2Hlqb7lNPWX+ Kbk92sLi1FukAqVtnCwJkerIJGwP7R5+9XXRPPWsNT4U3E1tFs9x73gkD2GxdAmg1JBF QCxQgNo2JQr+M2E6mPOm6kc6VMbya8EQaggBSaQpIAI9Gxlr5r7IH5bXr59MzyK14mjG F+sDgyIq7p3Hp16irk4HNMs9DjeijC2O5tzBeJMYHCIOGoJFbNWKTOpgOaQnYmejE005 WqwvTmKAa6JUg/+4mb3zdONLAnCNxkSwkhYODPH/a9d5X2+yonKGnaHFEIEt2aPcqprK si4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zM1PuCQO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id h8si204331pjs.13.2019.06.27.11.18.12; Thu, 27 Jun 2019 11:18:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zM1PuCQO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1726789AbfF0SQi (ORCPT + 99 others); Thu, 27 Jun 2019 14:16:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:47568 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726508AbfF0SQi (ORCPT ); Thu, 27 Jun 2019 14:16:38 -0400 Received: from kernel.org (unknown [104.132.0.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5EA752064A; Thu, 27 Jun 2019 18:16:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561659396; bh=2oWUiLUFI+CqOolaOKVa4jJ21rR9UR/fuLhE4nLYjdw=; h=In-Reply-To:References:To:From:Subject:Cc:Date:From; b=zM1PuCQOlI4msEkFixz730kc8/zFbvwJnRkqkjMyx+3IZ/8lQrJkX5bjK8+tcjTpD 9YTsqw4mLY9MvEtPAy8WslYPIgMqfSsLuNDFSuTYyeTtiNsbbEN2c2e7JVMq1S+AoJ JJirWvQWTUXBy4OsdUUrOSg+eULRykDPesnCIHuI= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: References: <20190617082613.109131-1-brendanhiggins@google.com> <20190617082613.109131-2-brendanhiggins@google.com> <20190620001526.93426218BE@mail.kernel.org> <20190626034100.B238520883@mail.kernel.org> To: Brendan Higgins From: Stephen Boyd Subject: Re: [PATCH v5 01/18] kunit: test: add KUnit test runner core Cc: Frank Rowand , Greg KH , Josh Poimboeuf , Kees Cook , Kieran Bingham , Luis Chamberlain , Peter Zijlstra , Rob Herring , shuah , Theodore Ts'o , Masahiro Yamada , devicetree , dri-devel , kunit-dev@googlegroups.com, "open list:DOCUMENTATION" , linux-fsdevel@vger.kernel.org, linux-kbuild , Linux Kernel Mailing List , "open list:KERNEL SELFTEST FRAMEWORK" , linux-nvdimm , linux-um@lists.infradead.org, Sasha Levin , "Bird, Timothy" , Amir Goldstein , Dan Carpenter , Daniel Vetter , Jeff Dike , Joel Stanley , Julia Lawall , Kevin Hilman , Knut Omang , Logan Gunthorpe , Michael Ellerman , Petr Mladek , Randy Dunlap , Richard Weinberger , David Rientjes , Steven Rostedt , wfg@linux.intel.com User-Agent: alot/0.8.1 Date: Thu, 27 Jun 2019 11:16:35 -0700 Message-Id: <20190627181636.5EA752064A@mail.kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Brendan Higgins (2019-06-26 16:00:40) > On Tue, Jun 25, 2019 at 8:41 PM Stephen Boyd wrote: >=20 > > scenario like below, but where it is a problem. There could be three > > CPUs, or even one CPU and three threads if you want to describe the > > extra thread scenario. > > > > Here's my scenario where it isn't needed: > > > > CPU0 CPU1 > > ---- ---- > > kunit_run_test(&test) > > test_case_func() > > .... > > [mock hardirq] > > kunit_set_success(&test) > > [hardirq ends] > > ... > > complete(&test_done) > > wait_for_completion(&test_done) > > kunit_get_success(&test) > > > > We don't need to care about having locking here because success or > > failure only happens in one place and it's synchronized with the > > completion. >=20 > Here is the scenario I am concerned about: >=20 > CPU0 CPU1 CPU2 > ---- ---- ---- > kunit_run_test(&test) > test_case_func() > .... > schedule_work(foo_func) > [mock hardirq] foo_func() > ... ... > kunit_set_success(false) kunit_set_success(= false) > [hardirq ends] ... > ... > complete(&test_done) > wait_for_completion(...) > kunit_get_success(&test) >=20 > In my scenario, since both CPU1 and CPU2 update the success status of > the test simultaneously, even though they are setting it to the same > value. If my understanding is correct, this could result in a > write-tear on some architectures in some circumstances. I suppose we > could just make it an atomic boolean, but I figured locking is also > fine, and generally preferred. This is what we have WRITE_ONCE() and READ_ONCE() for. Maybe you could just use that in the getter and setters and remove the lock if it isn't used for anything else. It may also be a good idea to have a kunit_fail_test() API that fails the test passed in with a WRITE_ONCE(false). Otherwise, the test is assumed successful and it isn't even possible for a test to change the state from failure to success due to a logical error because the API isn't available. Then we don't really need to have a generic kunit_set_success() function at all. We could have a kunit_test_failed() function too that replaces the kunit_get_success() function. That would read better in an if condition. >=20 > Also, to be clear, I am onboard with dropping then IRQ stuff for now. > I am fine moving to a mutex for the time being. >=20 Ok.