Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp5420150imm; Tue, 31 Jul 2018 10:34:32 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdtdshr4pFk9aLiZ+3hRgErZiJk+nBi0HmBkLFJsWlOpmyHeaoGLjnKIuQ+IlyT06YvV4LN X-Received: by 2002:a17:902:7c8e:: with SMTP id y14-v6mr21765195pll.265.1533058472309; Tue, 31 Jul 2018 10:34:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533058472; cv=none; d=google.com; s=arc-20160816; b=CtWGKh3+XaXcgtn5ruZmWq7sK6ksaoZ+/4Wk/wsC5x07ubQ+WVVP3A9m0tj8dkhzIy Ktqi/wOvlIxA5GZrIuM9s17fL/nSWkDySWXzTCxbfAMe1yRUsB4RsHlezu4TcWmvyatp Im2cvp3AUi76HbWIofzyDxgvC99xrogA0eXvWCPHHU8CjlyvvoyFscL+ysVMZ3kz6ffp YRmtswnpeWayUwWz2kS1JGLZ7rqVQaWouF1AA0aLbAvjTedmia8CuHSiqIsqXFdhZk95 WTsxlXpgNcifKUXwTUXnBa1TqheXGDtteeH0pVPCPlmBtZROtuTLCZ+cd7s6Q0o9mHAB Ut0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=Y1BnrtqVG/s28YgDNCfZ28RW59JM/ZDS0R3VqqeJLt8=; b=cYsm/zTn5KTrIxGmEfzIkq9h608QNuEjwQ2YXTWv8z3JEy3rek/l0qKAc2tVm+M/Mc fD5Z/2qpxUCqVgM2XMD3/dTyVexitusYCJgRLMhm61MoEJF2kYwcolijAysaGJ/Yac+7 FU3mrP8c8OglWLVJC/h7h+oeipzOaMWzIWONtU8CoyrkCB9c0ET5dGOIgfS3NtDjdGdt 5VsjgOsXrC4jg4uMeLXMevufoGmZ3UjJrYJh5NJV01qtzhzOQYYfvYVE3A3Q9mFHIXnb 0LmmoYkNG2+IH8n+EhY5iaFp3D9+2bSzjQvuOdZPbQV+W76ymKeZcfLOmyF0QK26lzSn nQBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Byu7vC6b; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o5-v6si12695545plk.25.2018.07.31.10.34.17; Tue, 31 Jul 2018 10:34:32 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=Byu7vC6b; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729935AbeGaTOM (ORCPT + 99 others); Tue, 31 Jul 2018 15:14:12 -0400 Received: from mail-it0-f66.google.com ([209.85.214.66]:55653 "EHLO mail-it0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729580AbeGaTOM (ORCPT ); Tue, 31 Jul 2018 15:14:12 -0400 Received: by mail-it0-f66.google.com with SMTP id p7-v6so5627237itf.5 for ; Tue, 31 Jul 2018 10:32:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Y1BnrtqVG/s28YgDNCfZ28RW59JM/ZDS0R3VqqeJLt8=; b=Byu7vC6bpS1kqBjTxluAR+SVN7KiD8TrA8F65lOG/AIYXmPJTyYpxqdQlBTmtW7Omi 7fXjSTneNj6+4T1AShb6eA53kKWnqRRA7i4bXcqjL21vtdM0qd3jpLONw4SZQuxPaY9t 7zVDxjXJXNgMVs4aiMu+ZIBK1I+DrMlS6XbCxtB0/MumzCEntMKqu9ON4l371jWrFoiq XvB8Dmj0yq5Mrr6YOEGMaNLrLhM9klXOTmSLjQhccUUbsLCoJYuDhw+iMehmGC9xon4R pdjSSxAyGGJ3+FmMzmpG35PH1kY+bEHrTjlGaojb9BsI7HvhpfLJ9g3fyO2MpSJY7/7u 53aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Y1BnrtqVG/s28YgDNCfZ28RW59JM/ZDS0R3VqqeJLt8=; b=inxPgi9smR9dweDswTPWfE2yLHLLNvRtlPEWXUOmuu9gdxmawn4hVYabwDvCFiOfzW Lq4YR3xAe4fI9agifEk8uNxgMDPOtCOTKo2pkrHmeCOJcSleuwttOrMSLNOikoWBOugX uf6SbxCo9EKifapy3QMCNag8TQRNySsrAX+yQu0F1RAYUkeDZx1hOk7GlNzNgPdaXrPI 6KnQUKRPAUMKfWCJoQ63rCVV2EMn/l6ygXjK/2ZBfXKh22h60U88VVoXKmYUOWT763+Q 5ELqKJAMs43Lg0HXZ+6Nw9GymHQn6FmTCcDgrbHOrMPNXy6bB/oOd7vkYu7KzDcFb3BY p0fw== X-Gm-Message-State: AOUpUlFEMJX4Q5lYpilZPQpMC5uI72+nAG99fMhz8rf3x8ui6j8gf9Nx 7/+Pfs1tl65Xf6LVHsKaxxOAePSrmRDRxZmjJRaqfQ== X-Received: by 2002:a24:5f92:: with SMTP id r140-v6mr579163itb.45.1533058370483; Tue, 31 Jul 2018 10:32:50 -0700 (PDT) MIME-Version: 1.0 References: <20180731170957.o4vhopmzgedpo5sh@breakpoint.cc> In-Reply-To: <20180731170957.o4vhopmzgedpo5sh@breakpoint.cc> From: Eric Dumazet Date: Tue, 31 Jul 2018 10:32:39 -0700 Message-ID: Subject: Re: SLAB_TYPESAFE_BY_RCU without constructors (was Re: [PATCH v4 13/17] khwasan: add hooks implementation) To: Florian Westphal Cc: Andrey Ryabinin , "Theodore Ts'o" , jack@suse.com, linux-ext4@vger.kernel.org, Greg Kroah-Hartman , Pablo Neira Ayuso , Jozsef Kadlecsik , David Miller , netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev , Gerrit Renker , dccp@vger.kernel.org, jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com, rodrigo.vivi@intel.com, airlied@linux.ie, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Alexey Kuznetsov , Hideaki YOSHIFUJI , Ursula Braun , linux-s390@vger.kernel.org, LKML , Dmitry Vyukov , Christoph Lameter , Andrew Morton , linux-mm , Andrey Konovalov , Linus Torvalds Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 31, 2018 at 10:10 AM Florian Westphal wrote: > > Andrey Ryabinin wrote: > > Guys, it seems that we have a lot of code using SLAB_TYPESAFE_BY_RCU cache without constructor. > > I think it's nearly impossible to use that combination without having bugs. > > It's either you don't really need the SLAB_TYPESAFE_BY_RCU, or you need to have a constructor in kmem_cache. > > > > Could you guys, please, verify your code if it's really need SLAB_TYPSAFE or constructor? > > > > E.g. the netlink code look extremely suspicious: > > > > /* > > * Do not use kmem_cache_zalloc(), as this cache uses > > * SLAB_TYPESAFE_BY_RCU. > > */ > > ct = kmem_cache_alloc(nf_conntrack_cachep, gfp); > > if (ct == NULL) > > goto out; > > > > spin_lock_init(&ct->lock); > > > > If nf_conntrack_cachep objects really used in rcu typesafe manner, than 'ct' returned by kmem_cache_alloc might still be > > in use by another cpu. So we just reinitialize spin_lock used by someone else? > > That would be a bug, nf_conn objects are reference counted. > > spinlock can only be used after object had its refcount incremented. > > lookup operation on nf_conn object: > 1. compare keys > 2. attempt to obtain refcount (using _not_zero version) > 3. compare keys again after refcount was obtained > > if any of that fails, nf_conn candidate is skipped. Yes, the key here is the refcount, this is only what we need to clear after kmem_cache_alloc() By definition, if an object is being freed/reallocated, the refcount should be already 0, and clearing it again is a NOP.