Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1903993imm; Thu, 27 Sep 2018 04:31:04 -0700 (PDT) X-Google-Smtp-Source: ACcGV623lye3Fhtljsm12HnKw0cLkOOOO3w4TGGMe/iiajUM4Au+H6K/6U+t042+NUnM2UAdAb9B X-Received: by 2002:a63:5816:: with SMTP id m22-v6mr9749905pgb.332.1538047864159; Thu, 27 Sep 2018 04:31:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538047864; cv=none; d=google.com; s=arc-20160816; b=b4apHF9BqyvnYkaVhlCI/rK1OcnhrTF0gmbuVOrrsLtUvQEAwEqgrBDKD5mck60ZD9 FxPlz/G2vKJ1I8+wGEt27mm+8WmEM2gptNhdPpyna4WitetbAwDPoV6tmxsHDZcMiOYl sy00IzXAQqlr9BCYUcSB3DM3oqjoa32YIwmAuoT9tQsD0ofs1j0zccooj4d7xHutHE6m QQccpebC4jFoQi5W2tXmoIho/povBVPA/MWtk2hlHAnqEEnCtiH9LoeIDFdtbgqWVxMX wRkqln5zeoTEv0G/BWgc6891XnGntlG9UQsy5u2JApCfcIl42dA+IT4e+VqEOoM8h4cF W2wA== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=VroWYwCsAplQaFET11YLP7vgfd083wyjDwL6h6ftWzk=; b=hWiHVjr6p7XNnIqrD0/6YYEFFZmD8fxBzZ2R9Ii5E/fwz3dOemzs6tSdVjGLJafeBd A/i/OR/9d9qNr0iUYzFwylUGFFTpK8jLwT2k5b6iKg8K/cp69Vo8Zi86LHm1Ynp8paQK xm+sVApGsbKO2MyCLrWlI9OggI5Yd2qZqoY3pfNpxGQ8y1DC4P55nHBEszzUk2N7+hNN 5pa8XMyFUL9klJx2LihWqDFlrJsZjsekP9bPeNES/UmBNuOMxD8U/XTnGsYY7yRDDSeQ 5m/Qds95X6Ay/+nOtgz1NcpbU11+EJvWEdidsDcaaYISiIgSOZbmC5USMwK8vPbRLy2G xaxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=KO6QKFrE; 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 p7-v6si1849938plo.159.2018.09.27.04.30.48; Thu, 27 Sep 2018 04:31:04 -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=@rasmusvillemoes.dk header.s=google header.b=KO6QKFrE; 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 S1727443AbeI0RsH (ORCPT + 99 others); Thu, 27 Sep 2018 13:48:07 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:34969 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727118AbeI0RsG (ORCPT ); Thu, 27 Sep 2018 13:48:06 -0400 Received: by mail-lj1-f194.google.com with SMTP id w4-v6so2054732ljd.2 for ; Thu, 27 Sep 2018 04:30:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=VroWYwCsAplQaFET11YLP7vgfd083wyjDwL6h6ftWzk=; b=KO6QKFrEZQNVhpHN3DMsoZK9e+oJXR9Yy1sxUCgrun4JmyuIOCc+/BUtiW/M2XkBse jCjPiCq+voPmfuyoi08H9ULMThuIfc4VVqq8M2GRVLPD5p6xzQVLTXprv99oKm4gHBAE aR1Z6HjB2GTL+nPGIj4hlLW2k6MM/Zg2FJStk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=VroWYwCsAplQaFET11YLP7vgfd083wyjDwL6h6ftWzk=; b=Uq8A8B/w5CvAyBlt8CtesVnlQH7tWwxD0o38QZLtR0OU2M8D99Wor9v8C6d4ETSEx3 z64Be5E0rOevu45rQO0cq7w3Q/Jq+oGB0R3Qf1u5HD2MJXV+/H6Mq6IUK3INSetiliyN MW160T3Fn3Z7P3QKCLR8aWdUayPpzGIXhsfNk7Wga3npiEZec0d+dEYCT48697WkDA6+ JC4V//xp0ItR5Z+7lfaxE7xyEzZ9b734obwTTl8ec39z+/WYegwfOdqlsGM+XlFOM82T lCAT/bnKAZnEFHzFm4Zd7053d4/aECgruP6n3NfdFtg7uxNiYuq+Ot/Zu2Ehkxc77dXQ bckw== X-Gm-Message-State: ABuFfogLQLUgugQbatXGKBgsQUJf5RBSR7TXGKwJG2ApKL/0Aztj6YL5 OReA2nep1IK3nIlDd0zWk4p1rA== X-Received: by 2002:a2e:360c:: with SMTP id d12-v6mr7488886lja.92.1538047815599; Thu, 27 Sep 2018 04:30:15 -0700 (PDT) Received: from [172.16.11.40] ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id g11-v6sm379245ljk.45.2018.09.27.04.30.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 04:30:14 -0700 (PDT) Subject: Re: [PATCH v3 3/4] devres: provide devm_kstrdup_const() To: Geert Uytterhoeven , Rasmus Villemoes Cc: Kees Cook , Bartosz Golaszewski , Michael Turquette , Stephen Boyd , Greg KH , "Rafael J. Wysocki" , Arend van Spriel , Ulf Hansson , Bjorn Helgaas , vivek.gautam@codeaurora.org, Robin Murphy , Joe Perches , Heikki Krogerus , Andrew Morton , Mike Rapoport , Michal Hocko , Al Viro , Jonathan Corbet , guro@fb.com, Huang Ying , =?UTF-8?Q?Bj=c3=b6rn_Andersson?= , Arnd Bergmann , Andy Shevchenko , linux-clk , Linux Kernel Mailing List , Linux MM References: <20180924101150.23349-1-brgl@bgdev.pl> <20180924101150.23349-4-brgl@bgdev.pl> <9ad301dc-47ef-cd7d-699d-e51716d1703f@rasmusvillemoes.dk> From: Rasmus Villemoes Message-ID: Date: Thu, 27 Sep 2018 13:30:13 +0200 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018-09-27 13:01, Geert Uytterhoeven wrote: > Hi Rasmus, > > On Thu, Sep 27, 2018 at 12:55 PM Rasmus Villemoes > wrote: >> On 2018-09-27 01:13, Kees Cook wrote: >> >> Just drop devm_kfree_const and teach devm_kfree to ignore >> is_kernel_rodata(). That avoids the 50-100 bytes of overhead for adding >> yet another EXPORT_SYMBOL and makes it easier to port drivers to >> devm_kstrdup_const (and avoids the bugs Kees is worried about). devm >> managed resources are almost never freed explicitly, so that single >> extra comparison in devm_kfree shouldn't matter for performance. > > I guess we can also teach kfree() to ignore is_kernel_rodata(), and > drop kfree_const()? In principle, yes, but the difference is that kfree() is called a lot more frequently, and on normal code paths, whereas devm_kfree is more often (though not always) called on error paths. The goal of _const variants of strdup is to save some memory, so one place to start is to reduce the .text overhead of that feature. And it avoids introducing subtle bugs if some devm_kfree() call is missed during conversion to devm_kstrdup_const(). Rasmus