Received: by 10.223.185.116 with SMTP id b49csp1094096wrg; Sat, 3 Mar 2018 15:22:47 -0800 (PST) X-Google-Smtp-Source: AG47ELtcGgZMg1ISqYJCUZJh7JospvNvw1uge9/3zjrjgxxeDUUJY0i/6sWZsJokPcnXmC32254k X-Received: by 10.99.152.70 with SMTP id l6mr8081361pgo.87.1520119367350; Sat, 03 Mar 2018 15:22:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520119367; cv=none; d=google.com; s=arc-20160816; b=BHZUJYtK5cT69BlKwHmu4pgThrjKPHEAsLpeeOLl00oLIOD31BWH63srlsrd0dBTtB dvjYP1kgXOcLZ7B8BjIYBxVLBXlte1x7Xp1cB/JeAT2Ys7/9tJFsDpSjugrIlYRjBqI5 zwPzelZGZ2WjxMO439HBDWlxHEaTfhQM/EOMkKiRsXSIUIXerqh5I2LIddJaYqIlpkTG gYPD/g6/tHWPvPS3AyYqTK+RDVlSeCf3+ABO8kOH9p2N0MfC514R5a4K9DdJQhCz8CpJ 7PA7E3ErVsG0OC2K/9lFoRhBu8KjXDrsmMIDobVuBIoXQn7qkRAZX/i7unRBz5cW7tSN 5Fig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=fponOKK/5WIOaqU94owvuW31e6lUE66U6gV7kHi4/Fc=; b=Aun1XqAI6mbyltOI3mfQUfN9iPyBDweql3zQh357cXOmWiQcSA3bFg8k85t+zMdgR1 6tMmpLvFIes3I1d7cmPEMmOERm5BunQtheIrS+ZjqKSUfJvAHbN8KcIQs3Ff615OZaVQ PqLWvRoL37uHzPd498bww7vqJ8e8mIhBZJvycaxwDPMTIaULfel83aOyliO2n+RO4k0I 5huQtjd8hO1eGfnlb8zdOluWvDVoB2tEAzswCDMmWvX42Z9O/UpYntSp52FFHM1jWOY7 0GkRcIykcSqwquBd3H9GA7IzQAD9RKDCBcIoYw0M8X9EC7BNC4BPAcx1Efe2ojWo4kRn yUpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=USoFVOxY; 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=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f5si6147730pgr.330.2018.03.03.15.22.33; Sat, 03 Mar 2018 15:22:47 -0800 (PST) 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=@microsoft.com header.s=selector1 header.b=USoFVOxY; 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=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934791AbeCCWh6 (ORCPT + 99 others); Sat, 3 Mar 2018 17:37:58 -0500 Received: from mail-co1nam03on0134.outbound.protection.outlook.com ([104.47.40.134]:45128 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934750AbeCCWhy (ORCPT ); Sat, 3 Mar 2018 17:37:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=fponOKK/5WIOaqU94owvuW31e6lUE66U6gV7kHi4/Fc=; b=USoFVOxYX9U2AG4+hy8GN2I4PE5/g/zfuvHboPvr9QcOW1f/oSvo6r+FlWqIbK0rouhrDzXyhy5rvCTYFufFomETmwI/GKDo0zRGdEFzKw0+aO8/6gFmXCVVjrMOJiszm3pPLRJmTWUTsEJytx9zkKHiooG0q29xBD/AXeUlulk= Received: from MW2PR2101MB1034.namprd21.prod.outlook.com (52.132.149.10) by MW2PR2101MB1100.namprd21.prod.outlook.com (52.132.149.29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.567.2; Sat, 3 Mar 2018 22:37:50 +0000 Received: from MW2PR2101MB1034.namprd21.prod.outlook.com ([fe80::1d56:338f:e2b:cec0]) by MW2PR2101MB1034.namprd21.prod.outlook.com ([fe80::1d56:338f:e2b:cec0%3]) with mapi id 15.20.0567.006; Sat, 3 Mar 2018 22:37:50 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Davidlohr Bueso , Davidlohr Bueso , "Paul E . McKenney" , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 218/219] locking/locktorture: Fix num reader/writer corner cases Thread-Topic: [PATCH AUTOSEL for 4.9 218/219] locking/locktorture: Fix num reader/writer corner cases Thread-Index: AQHTsz8sRxoEQAjVN0mTV3/6ThEeCA== Date: Sat, 3 Mar 2018 22:30:03 +0000 Message-ID: <20180303222716.26640-218-alexander.levin@microsoft.com> References: <20180303222716.26640-1-alexander.levin@microsoft.com> In-Reply-To: <20180303222716.26640-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;MW2PR2101MB1100;6:Qj55tl1dBbcd4MLeF807QEYY1wOzoe/qWX0VhC0sNbYuKbCgRWKYqpfnNhkfOngYtB3cVhrTR62mQNXzkJ1u+Fz1Nx/CA649PgAB9/qxLesrysZSIvtD0TSfBEQYzhd8JGAt1bdorgrTsOo1KKYY7PfZIXTA0yGD1lW9Y8GochXjiOb79/PJjDOzROMy3cbDJFTadFCLSNv6pzqa1NmyoAR643Y2PWJAdQvdVEF/0S+Sk1BEj4nS1dRcUNzpJX6EwyoB+256dUvw8l55oinMrTKguUw5brHhIhQ9t02n/9oUMi13oJ/SCrq4m6m0EL//Hwd8jmGpfSNXm8YFeBexrbYDA+hNuU5c4nZpXmgtmvHlPtqcU8Jcea1z+P1FgoV+;5:+QjPtx458KsBONM61iPgcRiAS3scxEMCc0POgafJ6IF9TY/ARPfiYILczfC/4kQYXNxLdn+srbktKdKXQWJvZRIWRtWVt2IRC0U9w3nukRxUySNOCEfKgJWXnTg7SarEsBLMyfTEwDW0jsJtJesJtKAZinSAElOOZH+MS3RjLCg=;24:ce2c1hlcPgrX9Sd7+Y+6mwMXB1316ssOP3zG14aLL079G7QVcMrW9rw7zaaYdymmTjfoH1IhTtenAT64mkn8Fq2UqxerFnLrIju2Svydrko=;7:dBfKqDb6QlQXlO8WqjZZQDD5F+WJe7bxBrNDOUObM7l3O//1bD8CQGtprzaQpkCUCFLIUuX4It85b3YXQoWq8VjcoTo9CEIbfvDLNX/2tKLOxcHIDJo9vlQJodHlKVm5eWa5uYxm+Lct2Yo47AA2h7xwu/XXeOYnRnN//ydDpD7TO5B64PNOCviXY+cR9KGIJ6Tjiv4FTeJUzkMyTpvWB1aDVHgrVVvf87282Zlcf9TeHNHilGma99H2T4H7WWo1 x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: a02476cd-ac75-4740-ea4b-08d581576595 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(5600026)(4604075)(3008032)(2017052603307)(7193020);SRVR:MW2PR2101MB1100; x-ms-traffictypediagnostic: MW2PR2101MB1100: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(180628864354917)(89211679590171)(104084551191319); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040501)(2401047)(5005006)(8121501046)(10201501046)(3002001)(3231220)(944501244)(52105095)(93006095)(93001095)(6055026)(61426038)(61427038)(6041288)(20161123560045)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(6072148)(201708071742011);SRVR:MW2PR2101MB1100;BCL:0;PCL:0;RULEID:;SRVR:MW2PR2101MB1100; x-forefront-prvs: 0600F93FE1 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39380400002)(376002)(39860400002)(396003)(366004)(346002)(199004)(189003)(22452003)(97736004)(7736002)(5250100002)(105586002)(2906002)(6506007)(72206003)(66066001)(59450400001)(4326008)(305945005)(10290500003)(186003)(3280700002)(102836004)(2950100002)(6666003)(2501003)(478600001)(26005)(2900100001)(10090500001)(53936002)(8676002)(25786009)(81166006)(81156014)(575784001)(54906003)(86362001)(6436002)(106356001)(110136005)(68736007)(36756003)(316002)(6512007)(5660300001)(107886003)(8936002)(1076002)(6486002)(3660700001)(99286004)(76176011)(3846002)(86612001)(14454004)(6116002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:MW2PR2101MB1100;H:MW2PR2101MB1034.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: 8OJ1xoKRvYayuf+c52tXLW3V+2MiZcomPghiD/fYoZwc5bJB/JbXcJkZzgwQYHhRkG6PLVajeP7VDPA6Ck7hymbqhRT/yh/NCvlM5KhCwy/orKBqf7NA8fK+rkgEhJRLmk71M4DSYpr63yTzLCVbMqxw3Im5eimKopcIWPRLwCw= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: a02476cd-ac75-4740-ea4b-08d581576595 X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Mar 2018 22:30:03.2133 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2PR2101MB1100 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Davidlohr Bueso [ Upstream commit 2ce77d16db4240dd2e422fc0a5c26d3e2ec03446 ] Things can explode for locktorture if the user does combinations of nwriters_stress=3D0 nreaders_stress=3D0. Fix this by not assuming we always want to torture writer threads. Reported-by: Jeremy Linton Signed-off-by: Davidlohr Bueso Signed-off-by: Paul E. McKenney Reviewed-by: Jeremy Linton Tested-by: Jeremy Linton Signed-off-by: Sasha Levin --- kernel/locking/locktorture.c | 76 +++++++++++++++++++++++++---------------= ---- 1 file changed, 44 insertions(+), 32 deletions(-) diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c index d3de04b12f8c..babc67cfed69 100644 --- a/kernel/locking/locktorture.c +++ b/kernel/locking/locktorture.c @@ -641,8 +641,7 @@ static void __torture_print_stats(char *page, { bool fail =3D 0; int i, n_stress; - long max =3D 0; - long min =3D statp[0].n_lock_acquired; + long max =3D 0, min =3D statp ? statp[0].n_lock_acquired : 0; long long sum =3D 0; =20 n_stress =3D write ? cxt.nrealwriters_stress : cxt.nrealreaders_stress; @@ -749,7 +748,7 @@ static void lock_torture_cleanup(void) * such, only perform the underlying torture-specific cleanups, * and avoid anything related to locktorture. */ - if (!cxt.lwsa) + if (!cxt.lwsa && !cxt.lrsa) goto end; =20 if (writer_tasks) { @@ -823,6 +822,13 @@ static int __init lock_torture_init(void) firsterr =3D -EINVAL; goto unwind; } + + if (nwriters_stress =3D=3D 0 && nreaders_stress =3D=3D 0) { + pr_alert("lock-torture: must run at least one locking thread\n"); + firsterr =3D -EINVAL; + goto unwind; + } + if (cxt.cur_ops->init) cxt.cur_ops->init(); =20 @@ -846,17 +852,19 @@ static int __init lock_torture_init(void) #endif =20 /* Initialize the statistics so that each run gets its own numbers. */ + if (nwriters_stress) { + lock_is_write_held =3D 0; + cxt.lwsa =3D kmalloc(sizeof(*cxt.lwsa) * cxt.nrealwriters_stress, GFP_KE= RNEL); + if (cxt.lwsa =3D=3D NULL) { + VERBOSE_TOROUT_STRING("cxt.lwsa: Out of memory"); + firsterr =3D -ENOMEM; + goto unwind; + } =20 - lock_is_write_held =3D 0; - cxt.lwsa =3D kmalloc(sizeof(*cxt.lwsa) * cxt.nrealwriters_stress, GFP_KER= NEL); - if (cxt.lwsa =3D=3D NULL) { - VERBOSE_TOROUT_STRING("cxt.lwsa: Out of memory"); - firsterr =3D -ENOMEM; - goto unwind; - } - for (i =3D 0; i < cxt.nrealwriters_stress; i++) { - cxt.lwsa[i].n_lock_fail =3D 0; - cxt.lwsa[i].n_lock_acquired =3D 0; + for (i =3D 0; i < cxt.nrealwriters_stress; i++) { + cxt.lwsa[i].n_lock_fail =3D 0; + cxt.lwsa[i].n_lock_acquired =3D 0; + } } =20 if (cxt.cur_ops->readlock) { @@ -873,19 +881,21 @@ static int __init lock_torture_init(void) cxt.nrealreaders_stress =3D cxt.nrealwriters_stress; } =20 - lock_is_read_held =3D 0; - cxt.lrsa =3D kmalloc(sizeof(*cxt.lrsa) * cxt.nrealreaders_stress, GFP_KE= RNEL); - if (cxt.lrsa =3D=3D NULL) { - VERBOSE_TOROUT_STRING("cxt.lrsa: Out of memory"); - firsterr =3D -ENOMEM; - kfree(cxt.lwsa); - cxt.lwsa =3D NULL; - goto unwind; - } - - for (i =3D 0; i < cxt.nrealreaders_stress; i++) { - cxt.lrsa[i].n_lock_fail =3D 0; - cxt.lrsa[i].n_lock_acquired =3D 0; + if (nreaders_stress) { + lock_is_read_held =3D 0; + cxt.lrsa =3D kmalloc(sizeof(*cxt.lrsa) * cxt.nrealreaders_stress, GFP_K= ERNEL); + if (cxt.lrsa =3D=3D NULL) { + VERBOSE_TOROUT_STRING("cxt.lrsa: Out of memory"); + firsterr =3D -ENOMEM; + kfree(cxt.lwsa); + cxt.lwsa =3D NULL; + goto unwind; + } + + for (i =3D 0; i < cxt.nrealreaders_stress; i++) { + cxt.lrsa[i].n_lock_fail =3D 0; + cxt.lrsa[i].n_lock_acquired =3D 0; + } } } =20 @@ -915,12 +925,14 @@ static int __init lock_torture_init(void) goto unwind; } =20 - writer_tasks =3D kzalloc(cxt.nrealwriters_stress * sizeof(writer_tasks[0]= ), - GFP_KERNEL); - if (writer_tasks =3D=3D NULL) { - VERBOSE_TOROUT_ERRSTRING("writer_tasks: Out of memory"); - firsterr =3D -ENOMEM; - goto unwind; + if (nwriters_stress) { + writer_tasks =3D kzalloc(cxt.nrealwriters_stress * sizeof(writer_tasks[0= ]), + GFP_KERNEL); + if (writer_tasks =3D=3D NULL) { + VERBOSE_TOROUT_ERRSTRING("writer_tasks: Out of memory"); + firsterr =3D -ENOMEM; + goto unwind; + } } =20 if (cxt.cur_ops->readlock) { --=20 2.14.1