Received: by 10.213.65.68 with SMTP id h4csp975739imn; Wed, 14 Mar 2018 06:05:39 -0700 (PDT) X-Google-Smtp-Source: AG47ELsX4KeseAPwqk0f7FsoLHK233n3dfSD2znDSeiFkMksaWRyV9rIvWTR+VdM7YY/Hv9NVqDD X-Received: by 2002:a17:902:464:: with SMTP id 91-v6mr4022182ple.126.1521032739043; Wed, 14 Mar 2018 06:05:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521032739; cv=none; d=google.com; s=arc-20160816; b=nqisVEbenbn6Pm+nz56gTOi0SZRYAjxxT6idd9y7C4qpNlI1AjkIrm21oubf30nCLh n3IEOFhUkDaFWkeNjVDsMNqhBduslmrLwUxjwedWSVMaNL/V8wyjLh8IkvndtmPSDAJ+ BUZZY5EvUZ8scgHm4QTGpyXNVKOq2quUq2VILX+5TRjS21AJMGiZnl8tR6jmt+wt1Y6P JEfSR0QB7NCLhP/mNAitg6vxCMgQhxWXPbnXDtCvAQIzGvRMX5HFyYI5LqR2xn6mGqNJ 8WR/PcgdnwBYcY8659JlNxpdtEiWcyPgJHTFdjJlFGyoT2eBx1eLQGCZH1nMN/juhCly zcGQ== 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:arc-authentication-results; bh=DvpnaiKAkZ5u4o0hy/Vw4uU9MPGyeESEcQ3LEDJ47/w=; b=nxmLWeUxhu6P4xKMNGXDAH6UkJDHZ8QGMgcHKsOgacv7vmEe76VPwOa8/KumgJEnAA Dv75Ckq83gaUR3ksNzduslxxz/3wMayeJgbu9/k1h+ple2cNX1Fccg4RldRovhleLevd zPTUjZtG0wmwIa5a0MVdebXUPt+0xUe6pfdpw/BEF72cI4N1YWSMrETD6hzVwFfPgn2N KysKDrmU55tcrO5+ER1/Eei5ZKUhABVox+L9KSEDbXOqXc6ZtwVlTS+j1FIbP8mZsLhs LnKfA4bFpMNCYQWusGnITMQgFS3mcXPBRDI42IOr3FJmEthUc1BUDxqP7AfA3u6Yapx4 YtJQ== 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 c5-v6si1931158plr.684.2018.03.14.06.04.57; Wed, 14 Mar 2018 06:05:39 -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 S1751386AbeCNNC6 (ORCPT + 99 others); Wed, 14 Mar 2018 09:02:58 -0400 Received: from lhrrgout.huawei.com ([194.213.3.17]:29337 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751480AbeCNNC5 (ORCPT ); Wed, 14 Mar 2018 09:02:57 -0400 Received: from LHREML711-CAH.china.huawei.com (unknown [172.18.7.108]) by Forcepoint Email with ESMTP id 9AE6791D42020; Wed, 14 Mar 2018 13:02:53 +0000 (GMT) Received: from [10.122.225.51] (10.122.225.51) by smtpsuk.huawei.com (10.201.108.34) with Microsoft SMTP Server (TLS) id 14.3.382.0; Wed, 14 Mar 2018 13:02:51 +0000 Subject: Re: [PATCH 5/8] Protectable Memory To: Matthew Wilcox CC: , , , , , , , , References: <20180313214554.28521-1-igor.stoppa@huawei.com> <20180313214554.28521-6-igor.stoppa@huawei.com> <20180314121547.GE29631@bombadil.infradead.org> From: Igor Stoppa Message-ID: Date: Wed, 14 Mar 2018 15:02:06 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <20180314121547.GE29631@bombadil.infradead.org> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.122.225.51] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 14/03/18 14:15, Matthew Wilcox wrote: > On Tue, Mar 13, 2018 at 11:45:51PM +0200, Igor Stoppa wrote: >> +static inline void *pmalloc_array(struct gen_pool *pool, size_t n, >> + size_t size, gfp_t flags) >> +{ >> + if (unlikely(!(pool && n && size))) >> + return NULL; > > Why not use the same formula as kvmalloc_array here? You've failed to > protect against integer overflow, which is the whole point of pmalloc_array. > > if (size != 0 && n > SIZE_MAX / size) > return NULL; oops :-( >> +static inline char *pstrdup(struct gen_pool *pool, const char *s, gfp_t gfp) >> +{ >> + size_t len; >> + char *buf; >> + >> + if (unlikely(pool == NULL || s == NULL)) >> + return NULL; > > No, delete these checks. They'll mask real bugs. I thought I got rid of all of them, but some have escaped me >> +static inline void pfree(struct gen_pool *pool, const void *addr) >> +{ >> + gen_pool_free(pool, (unsigned long)addr, 0); >> +} > > It's poor form to use a different subsystem's type here. It ties you > to genpool, so if somebody wants to replace it, you have to go through > all the users and change them. If you use your own type, it's a much > easier task. I thought about it, but typedef came to my mind and knowing it's usually frowned upon, I restrained myself. > struct pmalloc_pool { > struct gen_pool g; > } I didn't think this could be acceptable either. But if it is, then ok. > then: > > static inline void pfree(struct pmalloc_pool *pool, const void *addr) > { > gen_pool_free(&pool->g, (unsigned long)addr, 0); > } > > Looking further down, you could (should) move the contents of pmalloc_data > into pmalloc_pool; that's one fewer object to keep track of. > >> +struct pmalloc_data { >> + struct gen_pool *pool; /* Link back to the associated pool. */ >> + bool protected; /* Status of the pool: RO or RW. */ >> + struct kobj_attribute attr_protected; /* Sysfs attribute. */ >> + struct kobj_attribute attr_avail; /* Sysfs attribute. */ >> + struct kobj_attribute attr_size; /* Sysfs attribute. */ >> + struct kobj_attribute attr_chunks; /* Sysfs attribute. */ >> + struct kobject *pool_kobject; >> + struct list_head node; /* list of pools */ >> +}; > > sysfs attributes aren't free, you know. I appreciate you want something > to help debug / analyse, but having one file for the whole subsystem or > at least one per pool would be a better idea. Which means that it should not be normal sysfs, but rather debugfs, if I understand correctly, since in sysfs 1 value -> 1 file. -- igor