Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp603580imm; Wed, 1 Aug 2018 02:05:30 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdhlINyMl5w6PV0NRwuyr4fNS7QKAyRU+iE2HdixdHnEFlCxBCnPF4VWZ4XDvSHKoXkGXje X-Received: by 2002:a63:b445:: with SMTP id n5-v6mr24137833pgu.104.1533114330839; Wed, 01 Aug 2018 02:05:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533114330; cv=none; d=google.com; s=arc-20160816; b=F0kZWKzQw8n6FJH+dRtjO/iekaSF/6n6B3V4Sf/kaDeoMVs5Drx4qit2cTaun7mr8b bYpJXYobngeASb1KJ8BhJ87ong/cLcSsRd/8uXfsP/sOiwIWbC3UHkNP9+HrrtMHP9Dl OAE4eSGSLgSQN+2w9DIWY8CpNAv2aRQmIGNKofkx6Bdu2uwlFcghcwEc1ghrHA2YU5FS cnDMz8x/AJBnFcVgUwxDkT259XFL6CGiYZ5i2w612r1jQqfhOfrblo2PL95qTv8gxn62 N+p+ViiwtHwPdQ8rH5DwVy5aGZQRJnTA/aN1Cf55LD9uMEns+1jblVpmuLcHrUFSm2Kc Hcug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature:arc-authentication-results; bh=5/YT0Argz+VKm0ZzpyHcgTk855R+YuikgSgu9YuFAxc=; b=PIqkq0Fjqu9KNOAjfT6PZxSzv7N7eATCoU812eSa6tWOjLTqEzbQbUH03RbaEQF07K iQvG3A3O+okzVmnKyFlIrJbHNfDjpfrW5OAsNsns/BN9dUShmu1budml8HfRtYHL+xpG QEBaf8yM6oCewW07hHnSgxoQnVEil6zP97AEOSvP5HUompo09rlx89jSCAUWogmDkUBP BI6+se0cS53nsDvpgnc/YCmFPo/hUmgwbRwxLF6s5iG5VZGzeGMCigxsBURty5wL7+0R pvYgBRLEBTZSM1Gh8sZ9ozzxkY+A1LWrPGLNdC9KbTKSn+bqMrmg8/jiKSWOYWL0o/s4 rtAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=selector1 header.b=gfvu8iD4; 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=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m5-v6si13599857plt.468.2018.08.01.02.05.16; Wed, 01 Aug 2018 02:05:30 -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=@virtuozzo.com header.s=selector1 header.b=gfvu8iD4; 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=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388992AbeHAKsM (ORCPT + 99 others); Wed, 1 Aug 2018 06:48:12 -0400 Received: from mail-eopbgr20109.outbound.protection.outlook.com ([40.107.2.109]:23244 "EHLO EUR02-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388689AbeHAKsL (ORCPT ); Wed, 1 Aug 2018 06:48:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5/YT0Argz+VKm0ZzpyHcgTk855R+YuikgSgu9YuFAxc=; b=gfvu8iD4JqyVA9Cp9FZr+7e1hyJWAyvpRq66LeojA7bVEt1zl6v1l5/cK8XOTxvOG/cWguoKbt6UJlWbRwAyHhcC/wEFDsRh715cb3qHa8tVTxH6YEdVs4O3AMFrk21WixpHchzSM/KfUySpArN+3g4KmENujD6DD0pHgFccWNw= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=aryabinin@virtuozzo.com; Received: from [172.16.25.12] (185.231.240.5) by AM6PR08MB3256.eurprd08.prod.outlook.com (2603:10a6:209:47::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.995.20; Wed, 1 Aug 2018 09:03:19 +0000 Subject: Re: SLAB_TYPESAFE_BY_RCU without constructors (was Re: [PATCH v4 13/17] khwasan: add hooks implementation) To: Linus Torvalds , Christoph Lameter Cc: Theodore Ts'o , Jan Kara , linux-ext4@vger.kernel.org, Greg Kroah-Hartman , Pablo Neira Ayuso , Jozsef Kadlecsik , Florian Westphal , David Miller , NetFilter , coreteam@netfilter.org, Network Development , gerrit@erg.abdn.ac.uk, dccp@vger.kernel.org, Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Dave Airlie , intel-gfx , DRI , Eric Dumazet , Alexey Kuznetsov , Hideaki YOSHIFUJI , Ursula Braun , linux-s390 , Linux Kernel Mailing List , Dmitry Vyukov , Andrew Morton , linux-mm , Andrey Konovalov References: <01000164f169bc6b-c73a8353-d7d9-47ec-a782-90aadcb86bfb-000000@email.amazonses.com> From: Andrey Ryabinin Message-ID: <30ee6c72-dc90-275a-8e23-54221f393cb0@virtuozzo.com> Date: Wed, 1 Aug 2018 12:03:18 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [185.231.240.5] X-ClientProxiedBy: VI1PR0501CA0045.eurprd05.prod.outlook.com (2603:10a6:800:60::31) To AM6PR08MB3256.eurprd08.prod.outlook.com (2603:10a6:209:47::21) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 89e73043-1f89-4249-241d-08d5f78da1b9 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989117)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(2017052603328)(7153060)(7193020);SRVR:AM6PR08MB3256; X-Microsoft-Exchange-Diagnostics: 1;AM6PR08MB3256;3:TOmA5IbUbRMpsUPSmFAqd7o4OZJiXfKJpS8noosqHzzgUtCaguhmxbgXaSR/GlP663IvBLgX16/UQV0tkDfObZ9YEI4yR0lcCaSY/jL208+RbWZylhUEQRZdqtBsDoMAoTeu/3T1yqc2u618Cjy8IdQ2Vm5R5QkVHgJ89YctWDL4M/uEGvFtK9r4iWbmSd9wD0ViVyF9on5ogB5UuMVLyp+yoE27V+IXTRclbLkvv0ocYKSPyMPNgd6zqgRS9MbV;25:rW2GhM/qnOMoPGIx1FA+SaNciY51J/POumJBJZlOyeN2dw1W2CelA6qA3jj8eZp8qs/QPLdTAsjwL88AG+OlP4jPv26dYisxXqyli55LlmR9OrUH8efgHcJVRqTzh2i/O1hwvtKeKhTN03jE67kvandVMRy0IfsOB+Ix8aqrJ2zaylb5zyczoMeYAozc47TSjXW92yWfCmN4xW1F5d+Mdtd8RaNU3kHX8HEMoCl+dp9I4Skpnol/tgL/HBYWQelHyxCF6jusdH0rGM4MhaCUQ4L9t3/3cS7M9CsiIfGX2d4BZmJZ2Oo3ywn/a9sGijqXBFm9SNAjvR2FUlDUMV0//Q==;31:VykPdpnDkWY3dWKxvngqahLUz5ic9qltKnJiIfXQoojshVLX+yiZPEWiQGvl8DdZIDkyI5amJTrbYGESrfPb9GntcqfhnxQPGbxtWuLwD/cBgGX6wpG2P9dcblpA570YFZZICUROHRykPKdPMWd8S+q0b3iCRLWr0lbs9dVvyRVO7PXsiF+Uf+WVeIjxgBvqpd0wO0ocOE5MbSJqc7ifO+B+/7v0l6GSeiC+tDe5CW4= X-MS-TrafficTypeDiagnostic: AM6PR08MB3256: X-LD-Processed: 0bc7f26d-0264-416e-a6fc-8352af79c58f,ExtAddr X-Microsoft-Exchange-Diagnostics: 1;AM6PR08MB3256;20:iEtK/DV9DbI9/H3MlxoFHYmDk2/XILvQu28a2FnugkAbApu8tfSq6eiYFNGw6ToAX8v42oH1rpkrlc/8CwhZs1gy0uiheHqPucpTYM1wsNNP+EkGOi8rN3MyQNUq0nNelW6diEag0GIFO78bmH+Wa2XuYE7ngL0/6bJWUdsG3Sl/zMNQ+d/ATZNeTWaPrrsnlNITYg9GwuysZoBFZSyoC449FjWcRd1kt7WYMjp4lZtLUOSJnDyyf24P1sKlTIAqYcUhLhXOGvGKlJRTe/fiuLKc8iatdchFpJ0AL2rlWdHuSI8hLgccjTuVyxodhr8HBqeQ/Uj7kn/zcixHLFXILzi38K2VHG2R94jRNtDiikkx0AyLkwPLrKiTbZ7m7VbLUm3KCcOz2E/eLWSudHGgBqD5Ef2FwDYEnD6H+D1Ns8LmFSkBXEWWEv1by6b1LRO7URckvBspLr4h8k4s3I93Rimg1bahEN3KbZQ2OKycx8jpr/VRUejoKHJlPumF5vpf;4:RG0mp6q6oSshfmCM/H5qsIOTNQLOUpMnz1jzS8ZtVNHwmj5yiIaDD3Wcl+4y3d8Wk1VGKx9B8/kvzURLiPhf+HhGoHF+7pg0iudXKqMy9zaN3R/5qkawAmxgAhUd6aEns6/l5Sr3Kt8fsJaLZ2RBg0rTPmhiYaXj4DwRpVHc82+J8wPv3PRUdlG9CO70Vh7ubZhmpViVjGX/Da3Cvb7uW1I1/BzrKNw/xF2NRduUlxmTEUA7KQHoTAydc7nhdtxDnjVWC7PhgmD5zc2H8NmHww== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040522)(2401047)(8121501046)(5005006)(10201501046)(3002001)(93006095)(93001095)(3231311)(944501410)(52105095)(149027)(150027)(6041310)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123562045)(20161123558120)(6072148)(201708071742011)(7699016);SRVR:AM6PR08MB3256;BCL:0;PCL:0;RULEID:;SRVR:AM6PR08MB3256; X-Forefront-PRVS: 0751474A44 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6049001)(39840400004)(136003)(346002)(396003)(376002)(366004)(199004)(189003)(64126003)(105586002)(68736007)(106356001)(14444005)(11346002)(446003)(229853002)(2906002)(93886005)(31696002)(31686004)(956004)(2616005)(476003)(486006)(86362001)(4326008)(97736004)(25786009)(53936002)(8936002)(5660300001)(76176011)(65806001)(7416002)(7406005)(52116002)(81156014)(81166006)(23676004)(8676002)(65826007)(2486003)(52146003)(6116002)(3846002)(36756003)(6486002)(316002)(66066001)(230700001)(53546011)(386003)(47776003)(16526019)(186003)(65956001)(110136005)(58126008)(50466002)(6246003)(478600001)(26005)(77096007)(16576012)(305945005)(54906003)(7736002);DIR:OUT;SFP:1102;SCL:1;SRVR:AM6PR08MB3256;H:[172.16.25.12];FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtBTTZQUjA4TUIzMjU2OzIzOldUUTQyOTB4c05qazd5cTBzZEVLYXBpZGQ1?= =?utf-8?B?Ykc4WG95OWR3Z2JWOXhiR0xmcmZ4Q2lub1JlN2tDY2o0S0kxSllRMTRlNGkx?= =?utf-8?B?OVJYanBFSHdGTS9TMUNWcFBodUt2Wkg0Um9sVFV5aXpCdXdWMlpxWkU3TU40?= =?utf-8?B?N283VDVZRUd2RTA0NlM1d1ZHNllsVTkyTndvengwSHBiaVkvN0xvMUUrVStX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ydIAJSl59kIE=;7:SdYhnMglhaFVX9K0+Oe0omb9cY4JieHP02o7XmuCjGZXrAjz0ZkQWvqZ+cWQpPLMceemsZPjKttgB+pIzk8PWPXh26fEbB6oY3Ia0hz86pRcuSrSTOB/qDtHvEO7aPn50XmlL2825d+gHVE4ikbxFpvkddmxZQSNNjdc54Nl+lpwvkhTkw0NZaUyra3t3xJMyMN5GBJDu5tHsYmbf7s6nQ8aDfJwrwOeplv01peHAnVp7R5zqNhatj+M/HncqbW0 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;AM6PR08MB3256;20:URhqTSQ34AWjipgVH0GZa2K15OLeqCfePn+2scygb8LJklFdwXjURb3c56y8orPlYiCt3C6u3s+NGl+POHacJVyAYc5wK0mdaW+TxvNEHeG4WMU6BD0Nelm/DoOEMnNARw80fH8Tq6IQ65BzYzTuhVdzDM1zQwkSfJL19tXV6Ig= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Aug 2018 09:03:19.1298 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 89e73043-1f89-4249-241d-08d5f78da1b9 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3256 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/31/2018 09:51 PM, Linus Torvalds wrote: > On Tue, Jul 31, 2018 at 10:49 AM Linus Torvalds > wrote: >> >> So the re-use might initialize the fields lazily, not necessarily using a ctor. > > In particular, the pattern that nf_conntrack uses looks like it is safe. > > If you have a well-defined refcount, and use "atomic_inc_not_zero()" > to guard the speculative RCU access section, and use > "atomic_dec_and_test()" in the freeing section, then you should be > safe wrt new allocations. > > If you have a completely new allocation that has "random stale > content", you know that it cannot be on the RCU list, so there is no > speculative access that can ever see that random content. > > So the only case you need to worry about is a re-use allocation, and > you know that the refcount will start out as zero even if you don't > have a constructor. > > So you can think of the refcount itself as always having a zero > constructor, *BUT* you need to be careful with ordering. > > In particular, whoever does the allocation needs to then set the > refcount to a non-zero value *after* it has initialized all the other > fields. And in particular, it needs to make sure that it uses the > proper memory ordering to do so. > > And in this case, we have > > static struct nf_conn * > __nf_conntrack_alloc(struct net *net, > { > ... > atomic_set(&ct->ct_general.use, 0); > > which is a no-op for the re-use case (whether racing or not, since any > "inc_not_zero" users won't touch it), but initializes it to zero for > the "completely new object" case. > > And then, the thing that actually exposes it to the speculative walkers does: > > int > nf_conntrack_hash_check_insert(struct nf_conn *ct) > { > ... > smp_wmb(); > /* The caller holds a reference to this object */ > atomic_set(&ct->ct_general.use, 2); > > which means that it stays as zero until everything is actually set up, > and then the optimistic walker can use the other fields (including > spinlocks etc) to verify that it's actually the right thing. The > smp_wmb() means that the previous initialization really will be > visible before the object is visible. > > Side note: on some architectures it might help to make that "smp_wmb > -> atomic_set()" sequence be am "smp_store_release()" instead. Doesn't > matter on x86, but might matter on arm64. > > NOTE! One thing to be very worried about is that re-initializing > whatever RCU lists means that now the RCU walker may be walking on the > wrong list so the walker may do the right thing for this particular > entry, but it may miss walking *other* entries. So then you can get > spurious lookup failures, because the RCU walker never walked all the > way to the end of the right list. That ends up being a much more > subtle bug. > > But the nf_conntrack case seems to get that right too, see the restart > in ____nf_conntrack_find(). > > So I don't see anything wrong in nf_conntrack. > > But yes, using SLAB_TYPESAFE_BY_RCU is very very subtle. But most of > the subtleties have nothing to do with having a constructor, they are > about those "make sure memory ordering wrt refcount is right" and > "restart speculative RCU walk" issues that actually happen regardless > of having a constructor or not. > I see, thanks. I just don't see any point or advantage of *not* using the constructor with SLAB_TYPESAFE_BY_RCU caches. There is always must be a small part of initialization code that could be placed in constructor. And it's better to put that part into constructor to avoid initializing what's already has been initialized. If people use SLAB_TYPESAFE_BY_RCU instead of traditional kfree_rcu() for cache-efficiency and because they want to reuse the object faster, than avoiding few writes into cache-hot data doesn't look like a bad idea. E.g. nf_conntrack case could at least move the spin_lock_init() and atomic_set(&ct->ct_general.use, 0) in the constructor. I can't think of any advantage in not having the constructor.