Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp5423550imm; Tue, 31 Jul 2018 10:37:42 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdVUQ1pSfhug1qxO5cH55NGZt1Ukp8/YQykITkGBa2ned/GgQjvSlrwotcrwEP6SbgmuUyG X-Received: by 2002:a63:1b17:: with SMTP id b23-v6mr21543463pgb.275.1533058662821; Tue, 31 Jul 2018 10:37:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533058662; cv=none; d=google.com; s=arc-20160816; b=eAkK3G9s1OucCJ8aQ9+eOfdg+mSwDfOAQHmEr/ID1EpJSh+ZFR8DKQpjA11HyqD4QF lPrT/nPRzyOKEWGlhdHNxyyQItB/F6fLnMDxSw8qEyK0lKPWj0fYmalxEGG6Kb08ni7r vmWP0JVhTX5j/ZA7vg+ynjaQF+NgqJ4vJCck/rPu3WRhhHlkCB4RX2ZgdgV1ZLuZ/jnE 1/oxwJfQeeSlmr6GjEw0wJ+r+QHqHCcUlZi2xE+8KbtoxzOcI3BK2GNULno82ubeuNGD qL1gd1jGCHVfl9pBNlKOwjdq/1IuX/R3LvV0iNG2u2IzNV2zFKwhR83bEsk/yCEFwkgZ GwtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:feedback-id:mime-version:user-agent :references:message-id:in-reply-to:subject:cc:to:from:date :dkim-signature:arc-authentication-results; bh=rBTaFnpiVzIxulJ65dlOuvwq+Q64wHbJUpi/vqsce7g=; b=ItGIq5VmlJGhN3OpG2YjRuqe9yrOZKNbHitOigW1arl/En/pAZ0L+aAqMhw5/D9RrH j9HMxggKyhRizfZC+2bxEtrpAaQaPDVj/cFeQ4yo4Lg2s09Fr2NhWpDHgA8/K9oVcgQG 3F0WuVWTW/We/BWlz3UbZs3mlT7I26KoaGQxeqQb5XHVWR7mggD4WlI1cHbgXPUgUSQ0 LFKd25W7/0OTt4MVvzXXaiW+z/tcnXIW+DuR8y6LUH8XFJYAzr0SqDSkuH7XGPExwDA4 PjKDYJzr4JvOhtXBEFzcxABbBs10YpF30Ig1dgjeY4OsDqyyOoszXZC5aVwoKzuUXSA4 fjeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazonses.com header.s=ug7nbtf4gccmlpwj322ax3p6ow6yfsug header.b=S6ySXpXv; 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 i23-v6si14852110pgb.246.2018.07.31.10.37.28; Tue, 31 Jul 2018 10:37:42 -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=@amazonses.com header.s=ug7nbtf4gccmlpwj322ax3p6ow6yfsug header.b=S6ySXpXv; 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 S1731311AbeGaTR6 (ORCPT + 99 others); Tue, 31 Jul 2018 15:17:58 -0400 Received: from a9-92.smtp-out.amazonses.com ([54.240.9.92]:43154 "EHLO a9-92.smtp-out.amazonses.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728327AbeGaTR6 (ORCPT ); Tue, 31 Jul 2018 15:17:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=ug7nbtf4gccmlpwj322ax3p6ow6yfsug; d=amazonses.com; t=1533058596; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References:MIME-Version:Content-Type:Feedback-ID; bh=90HqWVTWMOjsJBf0Cfr1/WHlmUJGQ1TYHIcGVJupAFo=; b=S6ySXpXvndgph7eN1SPyT4oAf9N4Hbeq4QzGwi866kIXOXqqJmcFkTl8IQlGfuot HdHIsMhCdcqY8kfWmLbcc5FmCcuqdDI/yq+4F9pEhleQMmAVXKfp/lS2B7sZo/P7e7v /rxdpCFawSdaaq5wIyA6FwY+jeaL6qvVxUKblDPo= Date: Tue, 31 Jul 2018 17:36:36 +0000 From: Christopher Lameter X-X-Sender: cl@nuc-kabylake To: Andrey Ryabinin cc: Theodore Ts'o , Jan Kara , linux-ext4@vger.kernel.org, Greg Kroah-Hartman , Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , "David S. Miller" , netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, Gerrit Renker , dccp@vger.kernel.org, Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , David Airlie , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Eric Dumazet , Alexey Kuznetsov , Hideaki YOSHIFUJI , Ursula Braun , linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, Dmitry Vyukov , Andrew Morton , "linux-mm@kvack.org" , Andrey Konovalov , Linus Torvalds Subject: Re: SLAB_TYPESAFE_BY_RCU without constructors (was Re: [PATCH v4 13/17] khwasan: add hooks implementation) In-Reply-To: Message-ID: <01000164f169bc6b-c73a8353-d7d9-47ec-a782-90aadcb86bfb-000000@email.amazonses.com> References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-SES-Outgoing: 2018.07.31-54.240.9.92 Feedback-ID: 1.us-east-1.fQZZZ0Xtj2+TD7V5apTT/NrT6QKuPgzCT/IC7XYgDKI=:AmazonSES Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 31 Jul 2018, 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? ct may still be read by another cpu in a RCU section but the object was freed elsewhere so no other processor may modify the object. The lock must have been released before freeing the slab object and thus the initialization of the spinlock is unnecessary if it was initialized in ctor. If there is refcounting going on then why use SLAB_TYPESAFE_BY_RCU?