From patchwork Wed Oct 10 21:49:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Andrzej Siewior X-Patchwork-Id: 10635349 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 891CE16B1 for ; Wed, 10 Oct 2018 21:49:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 377DE2AB51 for ; Wed, 10 Oct 2018 21:49:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2741B2AB6A; Wed, 10 Oct 2018 21:49:52 +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 5A31C2AB51 for ; Wed, 10 Oct 2018 21:49:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4C6BD6B0003; Wed, 10 Oct 2018 17:49:50 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 475856B0005; Wed, 10 Oct 2018 17:49:50 -0400 (EDT) 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 3674A6B0006; Wed, 10 Oct 2018 17:49:50 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by kanga.kvack.org (Postfix) with ESMTP id D054D6B0003 for ; Wed, 10 Oct 2018 17:49:49 -0400 (EDT) Received: by mail-wr1-f69.google.com with SMTP id d29-v6so3996291wrc.3 for ; Wed, 10 Oct 2018 14:49:49 -0700 (PDT) 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:date:from:to :cc:subject:message-id:references:mime-version:content-disposition :in-reply-to:user-agent; bh=qKSH/KKh93CHTPaw7aZlnvdb1q+EcH/ZCdPFU1FIxNU=; b=ho5DjZy2Cb0yMhl/LsRil0sbaaP0EQ0rdCOO9NaHueSJ/DoxedhHdIyEwa0cY/NjbW pqcKisOjeLezrrbMi+TSI9GH9BctOXzI2960z4NPAifb3K68YHFV9tu55+e57T+cqdQt HvAACfDSLLqa3oClJKpF5vlphP7ZbtksTGweqajnK45HrLQ7kjB5Sq/44p0/G/+eZ7b2 XCGpAJurWENNGl+Yr5PtI1Q1ow+GHGdgX2NgueLnpkkBG1WCFwohGGjskuTPGSQ2BS8i uO1RxJAkfTVNJaTtYoOc/UPKJvC3zHS4EZ19G4U7Cgq5uishx2K/ua25deCTO+2iiP1b vuwg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bigeasy@linutronix.de designates 2a01:7a0:2:106d:700::1 as permitted sender) smtp.mailfrom=bigeasy@linutronix.de X-Gm-Message-State: ABuFfohHL9KbxOhMTaaSQ+VOOwY8+b4G81ql7sCJf4fcTH4S5aHT9ila dD2jaCzDRCoHz+ETTcFzVzsL6g9yzZ+nVhPIKq8flZJnGyAEWa2o/oENL4ZWa7vetjb7Np2t5Lh EpX/yqR1Pr+eRqRh984J1yPS9EquBpcOKpw2YetrVeQ8+4b2q9NMqNMRLU6iFWv8CvQ== X-Received: by 2002:adf:e9c7:: with SMTP id l7-v6mr23739986wrn.238.1539208189296; Wed, 10 Oct 2018 14:49:49 -0700 (PDT) X-Google-Smtp-Source: ACcGV63LCkqRJqRmdduZsKuX99hg1oDx5FRh7yi7d2VdGDAcbCphHHtFb7j9WUzyEd0XgiM0ON5U X-Received: by 2002:adf:e9c7:: with SMTP id l7-v6mr23739958wrn.238.1539208188253; Wed, 10 Oct 2018 14:49:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539208188; cv=none; d=google.com; s=arc-20160816; b=M6L/XnVi885Rjf83OjMTg2mPU0lTkPN+3HIpyq90deZdxIu7uz78xMU9rq3Ht+7fiw gtQcvtbkXGh+gJ7HV4qHj6K5q6axhUKFRnmmUEXmiUi2ns8TiRcLakUuoq6M8PhzDx/i EprCprhBEVVv9fsbSVo94AF12fgyXvODFaLFf+MzMesWhAaXwLCVtsRkLXzzIoYMO8SN XW1XHjZ6qKsd4AJTPtwXg+b5zT1asGdnfSjBbX2Sj/7EUz5OzlOMzxTTpXp5MWBfBEpd v4KzRR5P/i+T97SmBnsBIYtYkqoi77XTGqHCLA3m+3Ve7d1ltFsrDLXqhnf7OiSqe2r+ 8zzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date; bh=qKSH/KKh93CHTPaw7aZlnvdb1q+EcH/ZCdPFU1FIxNU=; b=0T9L4xNfU0h5Q7BBYiZzVuz9wIqKFazGtq5LO/pzNThaQSB6YdaaZdexUth6MduMfj iHIvEBAwBLSSOT20W7mnlEsQY4vSPYkbb+V3k4tZg6ns0t91DtDTGkGcJwNKHy/p8J0M WHFV65oRLE8wci43K9C11fHrBYkbX336Bz/UDupwMl7UaAWtgLkLdO+sU0UIS3NmmVdH U+tA1FpiTFL6mzNB403SK6JRQ03NlSkBlfJIBdqdxC9ADrORHOtRBjE5rX//xQnaE2ph qAcM7n73hz2NiAc7fgwD7rli76zqBNU0kU1nI9hpIGPad1HIAISm3lgsk06A+rLkMRPU Bkvg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of bigeasy@linutronix.de designates 2a01:7a0:2:106d:700::1 as permitted sender) smtp.mailfrom=bigeasy@linutronix.de Received: from Galois.linutronix.de (Galois.linutronix.de. [2a01:7a0:2:106d:700::1]) by mx.google.com with ESMTPS id d142-v6si15936936wme.102.2018.10.10.14.49.47 for (version=TLS1_2 cipher=AES128-SHA bits=128/128); Wed, 10 Oct 2018 14:49:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bigeasy@linutronix.de designates 2a01:7a0:2:106d:700::1 as permitted sender) client-ip=2a01:7a0:2:106d:700::1; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bigeasy@linutronix.de designates 2a01:7a0:2:106d:700::1 as permitted sender) smtp.mailfrom=bigeasy@linutronix.de Received: from bigeasy by Galois.linutronix.de with local (Exim 4.80) (envelope-from ) id 1gAMMT-0007Wo-Df; Wed, 10 Oct 2018 23:49:45 +0200 Date: Wed, 10 Oct 2018 23:49:45 +0200 From: Sebastian Andrzej Siewior To: Dmitry Vyukov Cc: Clark Williams , Alexander Potapenko , kasan-dev , Linux-MM , LKML , linux-rt-users@vger.kernel.org, Peter Zijlstra , Thomas Gleixner Subject: [PATCH] mm/kasan: make quarantine_lock a raw_spinlock_t Message-ID: <20181010214945.5owshc3mlrh74z4b@linutronix.de> References: <20180918152931.17322-1-williams@redhat.com> <20181005163018.icbknlzymwjhdehi@linutronix.de> <20181005163320.zkacovxvlih6blpp@linutronix.de> <20181009142742.ikh7xv2dn5skjjbe@linutronix.de> <20181010092929.a5gd3fkkw6swco4c@linutronix.de> <20181010095343.6qxved3owi6yokoa@linutronix.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 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 From: Clark Williams Date: Tue, 18 Sep 2018 10:29:31 -0500 The static lock quarantine_lock is used in quarantine.c to protect the quarantine queue datastructures. It is taken inside quarantine queue manipulation routines (quarantine_put(), quarantine_reduce() and quarantine_remove_cache()), with IRQs disabled. This is not a problem on a stock kernel but is problematic on an RT kernel where spin locks are sleeping spinlocks, which can sleep and can not be acquired with disabled interrupts. Convert the quarantine_lock to a raw spinlock_t. The usage of quarantine_lock is confined to quarantine.c and the work performed while the lock is held is used for debug purpose. Signed-off-by: Clark Williams Acked-by: Sebastian Andrzej Siewior [bigeasy: slightly altered the commit message] Signed-off-by: Sebastian Andrzej Siewior Acked-by: Dmitry Vyukov --- On 2018-10-10 11:57:41 [+0200], Dmitry Vyukov wrote: > Yes. Clark's patch looks good to me. Probably would be useful to add a > comment as to why raw spinlock is used (otherwise somebody may > refactor it back later). If you really insist, I could add something but this didn't happen so far. git's changelog should provide enough information why to why it was changed. mm/kasan/quarantine.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) --- a/mm/kasan/quarantine.c +++ b/mm/kasan/quarantine.c @@ -103,7 +103,7 @@ static int quarantine_head; static int quarantine_tail; /* Total size of all objects in global_quarantine across all batches. */ static unsigned long quarantine_size; -static DEFINE_SPINLOCK(quarantine_lock); +static DEFINE_RAW_SPINLOCK(quarantine_lock); DEFINE_STATIC_SRCU(remove_cache_srcu); /* Maximum size of the global queue. */ @@ -190,7 +190,7 @@ void quarantine_put(struct kasan_free_me if (unlikely(q->bytes > QUARANTINE_PERCPU_SIZE)) { qlist_move_all(q, &temp); - spin_lock(&quarantine_lock); + raw_spin_lock(&quarantine_lock); WRITE_ONCE(quarantine_size, quarantine_size + temp.bytes); qlist_move_all(&temp, &global_quarantine[quarantine_tail]); if (global_quarantine[quarantine_tail].bytes >= @@ -203,7 +203,7 @@ void quarantine_put(struct kasan_free_me if (new_tail != quarantine_head) quarantine_tail = new_tail; } - spin_unlock(&quarantine_lock); + raw_spin_unlock(&quarantine_lock); } local_irq_restore(flags); @@ -230,7 +230,7 @@ void quarantine_reduce(void) * expected case). */ srcu_idx = srcu_read_lock(&remove_cache_srcu); - spin_lock_irqsave(&quarantine_lock, flags); + raw_spin_lock_irqsave(&quarantine_lock, flags); /* * Update quarantine size in case of hotplug. Allocate a fraction of @@ -254,7 +254,7 @@ void quarantine_reduce(void) quarantine_head = 0; } - spin_unlock_irqrestore(&quarantine_lock, flags); + raw_spin_unlock_irqrestore(&quarantine_lock, flags); qlist_free_all(&to_free, NULL); srcu_read_unlock(&remove_cache_srcu, srcu_idx); @@ -310,17 +310,17 @@ void quarantine_remove_cache(struct kmem */ on_each_cpu(per_cpu_remove_cache, cache, 1); - spin_lock_irqsave(&quarantine_lock, flags); + raw_spin_lock_irqsave(&quarantine_lock, flags); for (i = 0; i < QUARANTINE_BATCHES; i++) { if (qlist_empty(&global_quarantine[i])) continue; qlist_move_cache(&global_quarantine[i], &to_free, cache); /* Scanning whole quarantine can take a while. */ - spin_unlock_irqrestore(&quarantine_lock, flags); + raw_spin_unlock_irqrestore(&quarantine_lock, flags); cond_resched(); - spin_lock_irqsave(&quarantine_lock, flags); + raw_spin_lock_irqsave(&quarantine_lock, flags); } - spin_unlock_irqrestore(&quarantine_lock, flags); + raw_spin_unlock_irqrestore(&quarantine_lock, flags); qlist_free_all(&to_free, cache);