Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1441189imm; Wed, 10 Oct 2018 14:50:36 -0700 (PDT) X-Google-Smtp-Source: ACcGV63Z6cy+ju7EnMlVnBhzeixL0EHmu9HvW6rKmZaJJSEWckOp5AoUNt1A8oB3JCSY5jX/zJ3j X-Received: by 2002:a62:ca4d:: with SMTP id n74-v6mr31482627pfg.10.1539208236778; Wed, 10 Oct 2018 14:50:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539208236; cv=none; d=google.com; s=arc-20160816; b=PCkfI3cQqveIwS4eFuvaiuwq/kvWFwLu4wv8678qjLWUefhKZHiXlnXJ/TKsq04Umx rsfwJKW/Pf5YIexbZzuskezJS/qZe2xsELsn1fJUAQ3ePbWw84/Ob3IIVRX6lpkPNLJs NSevFrZnB85KzT5vSzq8tkBZBHmkmxSz0N380HXO/wux2tKqViXgw90KTY8YbLtB7dUx ulWkgFeQTpDb+XMmE5VqAOCk8gGARsavXFp/BeO/2yKdBMK0JZ0jg6+B1yvx/Eb8la+t S1WuFDUosbyJrblyizLQgsdyyPdS2JyFfQlvgIrqX5MtnVB/S8ixI3w1/0hBL+3zNGi4 FulQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=qKSH/KKh93CHTPaw7aZlnvdb1q+EcH/ZCdPFU1FIxNU=; b=kwuLuryyLmYuArB3fZTn+TEO+7sxF43JcmprK69jEGLA8dVYF+pWMdZCt9lwtlHTrW zTOSocWItcV5b9Uf8El9qsp3ybGp3t1AKPjVdfehvcDBjzcb66RAHAFfR8Ip5OTqTDYR tH+3yRxJdKxI0xXuqBdfL9mxdUNM+w5/+PvAiUT/MCqYo/InwPtI/Yq854bheMNWZDjF 537B9zR9jcdXR/CU3kVJbGfKFT4BXR6FdRm0EvHVwBfwjtj/yJOytUajditDbEnCN5SZ zlsh8DVWdCSo1Lc5embao1rp4UhB/Jz/7upFy5Seft/eXQZtLZnufQrLkljoItBZoSrL i9IA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a59-v6si26664610pla.60.2018.10.10.14.50.21; Wed, 10 Oct 2018 14:50:36 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725916AbeJKFNz (ORCPT + 99 others); Thu, 11 Oct 2018 01:13:55 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:46374 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725856AbeJKFNy (ORCPT ); Thu, 11 Oct 2018 01:13:54 -0400 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-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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);