Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp654739imm; Fri, 5 Oct 2018 09:33:53 -0700 (PDT) X-Google-Smtp-Source: ACcGV62XI1Ca3Xvl/rPWUwROvkfITq45VRkwu7DLwexo7/qgc4fYCg4ZgrJsMCpYrVyvzrMzRUa2 X-Received: by 2002:a62:939d:: with SMTP id r29-v6mr12805897pfk.55.1538757233014; Fri, 05 Oct 2018 09:33:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538757232; cv=none; d=google.com; s=arc-20160816; b=ZLjw2ZHYap1LzAo08rp0gtsKY1hoLJi3WfYUEXld/cN4bW0EbebjjlixKvT2Rbb0FL ph4xcGdUqyl7eqZoD1716tJErSQdSslqoi5ZpIdmVfivS1sH6IhAJiNq8RVlxXBGb/6B c3f4si7fvbqV9rEDqlSsd0VtnD0aX05h0p5bHw+mjEkqHjaJSMXOdg00/wVAIIGannsC A+ZX3OdAyBJQiiSgo8lgAgViidTYYydZH8soen9ZkJdGFhcZMrFVgMaJSLjZbR4ec7yd 6LPOYhXhxYp3H9AR/igBLbwEkzSxLc6wRQXHjmrMZfkl607FDHd3Iawe4Vdesqnv0fQK SQFA== 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=tjJ2rST8PK1qF/gjNGWlnMQNoeM/ganIior+b4oGTG4=; b=PW2GvQT9TztCL2VLuacfS/A9smmHDpz7dO2dUg5vN99zHDfqb6LwBhK3o9Fw0igZ3Y 7SR5f96Ak/c/c0oyHs9q38Wh8Peg0n+5TCZbGFhOrRbENymtReQY6cV8t67tJGyRB841 W2BKCfEtEugecIxPOomCSh1wirtHx2MW3f07TPNtgpmR7fCzWWbz2aRMI2greTyP+VlP HsYi6KVigiJ/0lQwf3GvXgHqNOP1z0kKMK09Rk36T/E8J85er7i7C9RUO7s+cgwqvree tYc7K6cUGxDIj4COW7toOxkZJnA6l+Knk3QmvS7a6DqU5u8MMQGSp2XUqrVRBdE8/aNB Lwcw== 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 o5-v6si8447698plk.95.2018.10.05.09.33.37; Fri, 05 Oct 2018 09:33:52 -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 S1728921AbeJEXcx convert rfc822-to-8bit (ORCPT + 99 others); Fri, 5 Oct 2018 19:32:53 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:38635 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727572AbeJEXcw (ORCPT ); Fri, 5 Oct 2018 19:32:52 -0400 Received: from bigeasy by Galois.linutronix.de with local (Exim 4.80) (envelope-from ) id 1g8T2W-0004eM-Vw; Fri, 05 Oct 2018 18:33:21 +0200 Date: Fri, 5 Oct 2018 18:33:20 +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: <20181005163320.zkacovxvlih6blpp@linutronix.de> References: <20180918152931.17322-1-williams@redhat.com> <20181005163018.icbknlzymwjhdehi@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8BIT In-Reply-To: <20181005163018.icbknlzymwjhdehi@linutronix.de> 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-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