Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3017339imm; Sun, 7 Oct 2018 17:58:10 -0700 (PDT) X-Google-Smtp-Source: ACcGV63yU4XuGOOaCWjZZeRO0UlRux2qA6ivi2JRTgi/gSaOUxiRUfLRxFEv6PPNAkLIj1WRoD+z X-Received: by 2002:a62:fb04:: with SMTP id x4-v6mr8385553pfm.210.1538960290182; Sun, 07 Oct 2018 17:58:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538960290; cv=none; d=google.com; s=arc-20160816; b=oH55UW4BymSEfoLLeLBkyZL16hxcusnalp4/FDzHHG7jK84UZyzxJrWXLdT3YxcZDD yd3Cjtb7rg5snvAvbfMk8L6jmvG17HmWOsyMW50FK1cSuqiaScA4wf1NVUIxLfAGnYtQ 42BQ/Mz6Y/8NBbH9y8eOeO/9hySloJo9viUzBuywavWE6rm/dcaWyKqg52a9Blz96DIu WmgCrMXheirst3igT2KD7GWFky3RPB6E9VPkifi3HBf7ISU1c0xQ9EVVVs+BMzNDsHYf osRBCVYeZ+4iVV8gietvH1oqBiaBxUUK9CNkAQ2OxeLJtddb5Esoatoip0xSSLPmoK8k HBDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=5Gg3y8cnWPUCJN8TkD6DNWxZ6P52blZ4zXdO36sGC4M=; b=jMIwe59dqFYUVKLwbBI8AEJK3T0bUbr5rHlF+zY8INsKotZQ3DCdXNi7cvzd02YQ8b XTZBF5BBn3ctQ+hAcuzQUpS9mj7pJLw4ALugj36sulhH1b/kzkpGN1xg3IMUL5sgesrr 5edqfJo8vIm0fSUfD7HsjUShiNQKyRm0ckUyE/0wommr29ohH8AeEhafOxW4MQS1r24O 8amsB3312S1km/wTKt/moD6BXuN4iiwaZhsjgNXD1jX+VVBZF2ffVylmEMkjZXv6DvIP ZuH7cjhnDQ69Y1ofKVfSIIRqUWVVNtryjkuXVVZDEdrNEsIayq6tTWdVIiuvvqRFc/Dx GkHw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e17-v6si13139381pgv.54.2018.10.07.17.57.42; Sun, 07 Oct 2018 17:58:10 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726078AbeJHH4g convert rfc822-to-8bit (ORCPT + 99 others); Mon, 8 Oct 2018 03:56:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34238 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725834AbeJHH4g (ORCPT ); Mon, 8 Oct 2018 03:56:36 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9B1A6C04B928; Mon, 8 Oct 2018 00:47:29 +0000 (UTC) Received: from tagon (ovpn-120-183.rdu2.redhat.com [10.10.120.183]) by smtp.corp.redhat.com (Postfix) with ESMTP id 361112010D55; Mon, 8 Oct 2018 00:47:28 +0000 (UTC) Date: Sun, 7 Oct 2018 19:47:26 -0500 From: Clark Williams To: Sebastian Andrzej Siewior Cc: Alexander Potapenko , Dmitry Vyukov , kasan-dev@googlegroups.com, linux-mm@kvack.org, 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: <20181007194726.78d8464f@tagon> In-Reply-To: <20181005163320.zkacovxvlih6blpp@linutronix.de> References: <20180918152931.17322-1-williams@redhat.com> <20181005163018.icbknlzymwjhdehi@linutronix.de> <20181005163320.zkacovxvlih6blpp@linutronix.de> Organization: Red Hat, Inc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 08 Oct 2018 00:47:29 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I applied this patch to a fairly stock 4.18-rt5 kernel and booted with no complaints, then ran rteval for 12h with no stack splats reported. I'll keep banging on it but preliminary reports look good. Clark On Fri, 5 Oct 2018 18:33:20 +0200 Sebastian Andrzej Siewior wrote: > On 2018-10-05 18:30:18 [+0200], To Clark Williams wrote: > > 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… > > the patch at the bottom wouldn't work just fine for everyone. > It would have the beaty of annotating the locking scope a little and > avoiding the on_each_cpu() invocation. No local_irq_save() but actually > the proper locking primitives. > I haven't fully decoded the srcu part in the code. > > Wouldn't that work for you? > > Signed-off-by: Sebastian Andrzej Siewior > --- > mm/kasan/quarantine.c | 45 +++++++++++++++++++++++++------------------ > 1 file changed, 26 insertions(+), 19 deletions(-) > > diff --git a/mm/kasan/quarantine.c b/mm/kasan/quarantine.c > index 3a8ddf8baf7dc..8ed595960e3c1 100644 > --- a/mm/kasan/quarantine.c > +++ b/mm/kasan/quarantine.c > @@ -39,12 +39,13 @@ > * objects inside of it. > */ > struct qlist_head { > + spinlock_t lock; > struct qlist_node *head; > struct qlist_node *tail; > size_t bytes; > }; > > -#define QLIST_INIT { NULL, NULL, 0 } > +#define QLIST_INIT {.head = NULL, .tail = NULL, .bytes = 0 } > > static bool qlist_empty(struct qlist_head *q) > { > @@ -95,7 +96,9 @@ static void qlist_move_all(struct qlist_head *from, struct qlist_head *to) > * The object quarantine consists of per-cpu queues and a global queue, > * guarded by quarantine_lock. > */ > -static DEFINE_PER_CPU(struct qlist_head, cpu_quarantine); > +static DEFINE_PER_CPU(struct qlist_head, cpu_quarantine) = { > + .lock = __SPIN_LOCK_UNLOCKED(cpu_quarantine.lock), > +}; > > /* Round-robin FIFO array of batches. */ > static struct qlist_head global_quarantine[QUARANTINE_BATCHES]; > @@ -183,12 +186,13 @@ void quarantine_put(struct kasan_free_meta *info, struct kmem_cache *cache) > * beginning which ensures that it either sees the objects in per-cpu > * lists or in the global quarantine. > */ > - local_irq_save(flags); > + q = raw_cpu_ptr(&cpu_quarantine); > + spin_lock_irqsave(&q->lock, flags); > > - q = this_cpu_ptr(&cpu_quarantine); > qlist_put(q, &info->quarantine_link, cache->size); > if (unlikely(q->bytes > QUARANTINE_PERCPU_SIZE)) { > qlist_move_all(q, &temp); > + spin_unlock(&q->lock); > > spin_lock(&quarantine_lock); > WRITE_ONCE(quarantine_size, quarantine_size + temp.bytes); > @@ -203,10 +207,10 @@ 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); > + spin_unlock_irqrestore(&quarantine_lock, flags); > + } else { > + spin_unlock_irqrestore(&q->lock, flags); > } > - > - local_irq_restore(flags); > } > > void quarantine_reduce(void) > @@ -284,21 +288,11 @@ static void qlist_move_cache(struct qlist_head *from, > } > } > > -static void per_cpu_remove_cache(void *arg) > -{ > - struct kmem_cache *cache = arg; > - struct qlist_head to_free = QLIST_INIT; > - struct qlist_head *q; > - > - q = this_cpu_ptr(&cpu_quarantine); > - qlist_move_cache(q, &to_free, cache); > - qlist_free_all(&to_free, cache); > -} > - > /* Free all quarantined objects belonging to cache. */ > void quarantine_remove_cache(struct kmem_cache *cache) > { > unsigned long flags, i; > + unsigned int cpu; > struct qlist_head to_free = QLIST_INIT; > > /* > @@ -308,7 +302,20 @@ void quarantine_remove_cache(struct kmem_cache *cache) > * achieves the first goal, while synchronize_srcu() achieves the > * second. > */ > - on_each_cpu(per_cpu_remove_cache, cache, 1); > + /* get_online_cpus() invoked by caller */ > + for_each_online_cpu(cpu) { > + struct qlist_head *q; > + unsigned long flags; > + struct qlist_head to_free = QLIST_INIT; > + > + q = per_cpu_ptr(&cpu_quarantine, cpu); > + spin_lock_irqsave(&q->lock, flags); > + qlist_move_cache(q, &to_free, cache); > + spin_unlock_irqrestore(&q->lock, flags); > + > + qlist_free_all(&to_free, cache); > + > + } > > spin_lock_irqsave(&quarantine_lock, flags); > for (i = 0; i < QUARANTINE_BATCHES; i++) { > -- > 2.19.0 > -- The United States Coast Guard Ruining Natural Selection since 1790