From patchwork Mon Nov 19 18:55:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Waiman Long X-Patchwork-Id: 10689301 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 11A0F5A4 for ; Mon, 19 Nov 2018 18:56:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 02EF12A453 for ; Mon, 19 Nov 2018 18:56:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EAC122A462; Mon, 19 Nov 2018 18:56:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D7B52A465 for ; Mon, 19 Nov 2018 18:56:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 59FE66B1B87; Mon, 19 Nov 2018 13:56:52 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 54EF26B1B88; Mon, 19 Nov 2018 13:56:52 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 43F056B1B89; Mon, 19 Nov 2018 13:56:52 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by kanga.kvack.org (Postfix) with ESMTP id 1AB366B1B87 for ; Mon, 19 Nov 2018 13:56:52 -0500 (EST) Received: by mail-qk1-f198.google.com with SMTP id z68so46720610qkb.14 for ; Mon, 19 Nov 2018 10:56:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id; bh=fwAWSFGSr9E0PkzO8JXDDbkJAIuKBr8UtikMZdinGG4=; b=TpcwcbGxXTyMbEXFDar+0bDCWB6Onkyj4vmxP8xjr5rym5JF1eV/gIhn3/HOqiUR08 jZo0GNlcAmW52yeWoQnMz+sPsgDubvfUKG4pXTepUzWs+HskWoi2ogOggoa7pPBMZcrJ G6hE2PChHFyOOjhrSKFpeDdyPRJyZtJzSGkXNtKfgX6+MquQu7NGSXhGdvqGtAhhrdK+ WXu2p0TP4PZkdNEd7JmVvoXJMqEoCqpiDtXOU3VFTfZ2Jd0pPq5lZeIuzM7NpmXZ0Nrz hINNCaKKysTvHmAETW/+vPxt8t/GUOqXXf9cQoONlopek+cSjeKJc3/4cyyDqccCbdR+ rqSA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of longman@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=longman@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AGRZ1gJh45mOFYE/XZ0t18zb5fc5mIGSj6jhQFn9O3+U1JPcygX86tGN 1/E6Pp8UmH7TVKCr8ZEZHPNY0DeeAMrBfxaQliRFDdG/jWlsBH8OHKujU0Gisk9tWfRMxp71yCr Y0+cgszwxAmFn4HY3RDqdnWo+oedxCwgcB40jvJLQet96oUTyteola0rvFa70VuatnA== X-Received: by 2002:ae9:e102:: with SMTP id g2mr20481037qkm.343.1542653811832; Mon, 19 Nov 2018 10:56:51 -0800 (PST) X-Google-Smtp-Source: AJdET5fXamxljp/bd2HRQz4TU/6gIm9KICXuAEVLvVwtLfNkmHEA0R4PidtDV252T6XyVtjVs/R4 X-Received: by 2002:ae9:e102:: with SMTP id g2mr20481007qkm.343.1542653810895; Mon, 19 Nov 2018 10:56:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542653810; cv=none; d=google.com; s=arc-20160816; b=0IZL/0cKkH5ZEWPGzn9HD+ZLgKjNSgmfpS1HPG5fR3j1yER2550jJKH9s0HaEfan27 m683rQiDHcuqWrAyQVCgaVKSiCIJ6SHG7Wg7LeCE2x/ZjTGscBIpWDHmLDcHDV+TnfjG kqIStrYIPY+zyanriCxD6t2Zd/D8jKE0Kqr1zuHF1FmlO3PsDd+T0yq2Iqgm162o/Dy/ x9lvhGntba5wMUmsidimaXMu8nd0nDL1N/TMwGFVds2InL8/bel8KwxJKGi//ISfFeAj nVTfoXkvCt1CKrO2Lr7bsVsEnWkPMy5HeOmEOFa3mWEtOUfxVqVRsRm9hTuJItDNWz9A Vxiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from; bh=fwAWSFGSr9E0PkzO8JXDDbkJAIuKBr8UtikMZdinGG4=; b=npANaon3ffT1iWqyXk7gtxGyhHCciA7iZPwk56RHQiA4XAN2bD+Mp1EmfbzTlR4c96 nJJDshOqBl/CyPSYugb4UYZFTRS4uNHZXKPbDpQ5I6x8/kzqv+36vSmtK1Dailurgv7S 15Dna5ksZVGLj1scaRdWu72movK86fMJoPfiIwCRJRV3SNvCxMNjeaOOcJRrcOjJ/5zl B6sPc6LJ9s6aKzflH7GO4aQCkyuBHv88qTrNT1iLZbU8wLY+qXD0g7QKM084X8M1pbB8 8lazHGsrSj29+xHygRFdzR4gZDfPyV0uA/dy2LcbblB66RkhLDEHjmyzoy/puIupoNOD nmpQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of longman@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=longman@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id l91si2515667qtd.76.2018.11.19.10.56.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Nov 2018 10:56:50 -0800 (PST) Received-SPF: pass (google.com: domain of longman@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of longman@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=longman@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C067D3097022; Mon, 19 Nov 2018 18:56:49 +0000 (UTC) Received: from llong.com (dhcp-17-55.bos.redhat.com [10.18.17.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0C74B648A8; Mon, 19 Nov 2018 18:56:43 +0000 (UTC) From: Waiman Long To: Peter Zijlstra , Ingo Molnar , Will Deacon , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, iommu@lists.linux-foundation.org, Petr Mladek , Sergey Senozhatsky , Andrey Ryabinin , Tejun Heo , Andrew Morton , Waiman Long Subject: [PATCH v2 00/17] locking/lockdep: Add a new class of terminal locks Date: Mon, 19 Nov 2018 13:55:09 -0500 Message-Id: <1542653726-5655-1-git-send-email-longman@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Mon, 19 Nov 2018 18:56:50 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP v1->v2: - Mark more locks as terminal. - Add a patch to remove the unused version field from lock_class. - Steal some bits from pin_count of held_lock for flags. - Add a patch to warn if a task holding a raw spinlock is acquiring an non-raw lock. The purpose of this patchset is to add a new class of locks called terminal locks and converts some of the low level raw or regular spinlocks to terminal locks. A terminal lock does not have forward dependency and it won't allow a lock or unlock operation on another lock. Two level nesting of terminal locks is allowed, though. Only spinlocks that are acquired with the _irq/_irqsave variants or acquired in an IRQ disabled context should be classified as terminal locks. Because of the restrictions on terminal locks, we can do simple checks on them without using the lockdep lock validation machinery. The advantages of making these changes are as follows: 1) It saves table entries used by the validation code and hence make it harder to overflow those tables. 2) The lockdep check in __lock_acquire() will be a little bit faster for terminal locks without using the lock validation code. In fact, it is possible to overflow some of the tables by running a variety of different workloads on a debug kernel. I have seen bug reports about exhausting MAX_LOCKDEP_KEYS, MAX_LOCKDEP_ENTRIES and MAX_STACK_TRACE_ENTRIES. This patch will help to reduce the chance of overflowing some of the tables. Below were selected output lines from the lockdep_stats files of the patched and unpatched kernels after bootup and running parallel kernel builds and some perf benchmarks. Item Unpatched kernel Patched kernel % Change ---- ---------------- -------------- -------- direct dependencies 9924 9032 -9.0% dependency chains 18258 16326 -10.6% dependency chain hlocks 73198 64927 -11.3% stack-trace entries 110502 103225 -6.6% There were some reductions in the size of the lockdep tables. They were not significant, but it is still a good start to rein in the number of entries in those tables to make it harder to overflow them. In term of performance, there isn't that much noticeable differences in both the kernel build and perf benchmark. Low level locking microbenchmark with 4 locking threads shows the following locking rates on a Haswell system: Kernel Lock Rate ------ ---- ---- Unpatched kernel Regular lock 2,288 kop/s Patched kernel Regular lock 2,352 kop/s Terminal lock 2,512 kop/s I was not sure why there was a slight performance improvement with the patched kernel. However, comparing the regular and terminal lock results, there was a slight 7% improvement in locking throughput for terminal locks. Looking at the perf ouput for regular lock: 5.43% run-locktest [kernel.vmlinux] [k] __lock_acquire 4.65% run-locktest [kernel.vmlinux] [k] lock_contended 2.80% run-locktest [kernel.vmlinux] [k] lock_acquired 2.53% run-locktest [kernel.vmlinux] [k] lock_release 1.42% run-locktest [kernel.vmlinux] [k] mark_lock For terminal lock: 5.00% run-locktest [kernel.vmlinux] [k] __lock_acquire 4.66% run-locktest [kernel.vmlinux] [k] lock_contended 2.88% run-locktest [kernel.vmlinux] [k] lock_acquired 2.55% run-locktest [kernel.vmlinux] [k] lock_release 1.34% run-locktest [kernel.vmlinux] [k] mark_lock The __lock_acquire() function ran a bit faster with terminal lock, but the other lockdep functions remain more or less the same in term of performance. In term internal lockdep structure sizes, there should be no size increase for 64-bit architectures with CONFIG_LOCK_STAT defined. The lockdep_map structure will increase in size for 32-bit architectures or when CONFIG_LOCK_STAT isn't defined. Waiman Long (17): locking/lockdep: Remove version from lock_class structure locking/lockdep: Rework lockdep_set_novalidate_class() locking/lockdep: Add a new terminal lock type locking/lockdep: Add DEFINE_TERMINAL_SPINLOCK() and related macros printk: Mark logbuf_lock & console_owner_lock as terminal locks debugobjects: Mark pool_lock as a terminal lock debugobjects: Move printk out of db lock critical sections locking/lockdep: Add support for nestable terminal locks debugobjects: Make object hash locks nestable terminal locks lib/stackdepot: Make depot_lock a terminal spinlock locking/rwsem: Mark rwsem.wait_lock as a terminal lock cgroup: Mark the rstat percpu lock as terminal mm/kasan: Make quarantine_lock a terminal lock dma-debug: Mark free_entries_lock as terminal kernfs: Mark kernfs_open_node_lock as terminal lock delay_acct: Mark task's delays->lock as terminal spinlock locking/lockdep: Check raw/non-raw locking conflicts fs/kernfs/file.c | 2 +- include/linux/lockdep.h | 59 +++++++++++++++++++++++---- include/linux/rwsem.h | 11 +++++- include/linux/spinlock_types.h | 34 ++++++++++------ kernel/cgroup/rstat.c | 9 ++++- kernel/delayacct.c | 4 +- kernel/dma/debug.c | 2 +- kernel/locking/lockdep.c | 81 ++++++++++++++++++++++++++++++++------ kernel/locking/lockdep_internals.h | 5 +++ kernel/locking/lockdep_proc.c | 11 +++++- kernel/locking/rwsem-xadd.c | 1 + kernel/locking/spinlock_debug.c | 1 + kernel/printk/printk.c | 4 +- kernel/printk/printk_safe.c | 2 +- lib/debugobjects.c | 70 ++++++++++++++++++++++---------- lib/stackdepot.c | 2 +- mm/kasan/quarantine.c | 2 +- 17 files changed, 235 insertions(+), 65 deletions(-)