Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp652778imm; Fri, 5 Oct 2018 09:32:04 -0700 (PDT) X-Google-Smtp-Source: ACcGV63djXBoyaCt9CfnFr1St6+1XZB+TExXtrSou90UUm+zLjjSJRaTCNAdSkrtR5i7bcpbfDv6 X-Received: by 2002:a62:8a4f:: with SMTP id y76-v6mr12935796pfd.142.1538757124319; Fri, 05 Oct 2018 09:32:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538757124; cv=none; d=google.com; s=arc-20160816; b=DZegBkJUrzKLMgmjSElgYJBkQGU91yMZu2LUMc8Z9McTEeCIQ3ESQ/LwqdsW2y5PNv WtpVvjs1piude14FT/EiKmLqNMAmVhBbQH4cv1tzezz96Rv35+OkmhqURYfBtYPpPBMQ E43MtJNOiJLAIC+U/8lFf0P66QLBNaINMb18areIP/WTyBS0KqjbeClptlJda4hRHc6y FnHNlxLJN1jZvQuzKNfZcQfLqe2A/V4vu3JF2Nk3Y+MkbUzTIVwFJSWc+CP/SgZM9MSK B8N+J3s8MYhSG4pmxmFMZPU/ojeacC5T8vzSWL0WOn7psDQ7EvxUQh2hfBI6/a891bTl 8swg== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=Ab6Bh3dimAhYDbdxlQ/i0N6lrycg6g4si2Goe/vkQHc=; b=Ohwox7Ny1Qhkn+bQJoeD0rl3KwDJzCuT2ENyLh/DxVliYZZINIlOp2/iQQyoJuw79k lJ5Nin3PZ+8gU7YNa0AmYz+dMMbR/Gd1iOCHLyslHyLF47OU9V5VI7paIOuQQ/AXi32Z 4ip1EXbBQ+tcb3u95bylBZjCGQK6Vj/Npjd1NH4EM/+phuASr0PG0dYemsjMpc7nFyrk SxhTNQvGxz+2g31e2WVvK7qImhlMxBm67f4IQSbhfhuJMpOW2+J7QGW4+Zb/hbVh+NH1 ALz2K4dEMry2i8bZEMG+TYG1SZlNQ7LwqWQbI8mc9Rcq1DmDpfXWjyWmVod6oYyYrjxJ RtSQ== 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 n10-v6si8353549pgj.165.2018.10.05.09.31.47; Fri, 05 Oct 2018 09:32:04 -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 S1728835AbeJEX3w convert rfc822-to-8bit (ORCPT + 99 others); Fri, 5 Oct 2018 19:29:52 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:38623 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727941AbeJEX3w (ORCPT ); Fri, 5 Oct 2018 19:29:52 -0400 Received: from bigeasy by Galois.linutronix.de with local (Exim 4.80) (envelope-from ) id 1g8Sza-0004br-HT; Fri, 05 Oct 2018 18:30:18 +0200 Date: Fri, 5 Oct 2018 18:30:18 +0200 From: Sebastian Andrzej Siewior To: Clark Williams , Alexander Potapenko , Dmitry Vyukov , kasan-dev@googlegroups.com, linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, linux-rt-users@vger.kernel.org, Peter Zijlstra , Thomas Gleixner Subject: Re: [PATCH] kasan: convert kasan/quarantine_lock to raw_spinlock Message-ID: <20181005163018.icbknlzymwjhdehi@linutronix.de> References: <20180918152931.17322-1-williams@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8BIT In-Reply-To: <20180918152931.17322-1-williams@redhat.com> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018-09-18 10:29:31 [-0500], Clark Williams wrote: So I received this from Clark: > The static lock quarantine_lock is used in mm/kasan/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 no problem on a stock kernel but is problematic > on an RT kernel where spin locks are converted to rt_mutex_t, which can sleep. > > Convert the quarantine_lock to a raw spinlock. The usage of quarantine_lock > is confined to quarantine.c and the work performed while the lock is held is limited. > > Signed-off-by: Clark Williams This is the minimum to get this working on RT splat free. There is one memory deallocation with irqs off which should work on RT in its current way. Once this and the on_each_cpu() invocation, I was wondering if… > --- > mm/kasan/quarantine.c | 18 +++++++++--------- > 1 file changed, 9 insertions(+), 9 deletions(-) > > diff --git a/mm/kasan/quarantine.c b/mm/kasan/quarantine.c > index 3a8ddf8baf7d..b209dbaefde8 100644 > --- 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_meta *info, struct kmem_cache *cache) > 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_meta *info, struct kmem_cache *cache) > 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_cache *cache) > */ > 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); > > -- > 2.17.1 > Sebastian