From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EAAC4C433F5 for ; Tue, 22 Mar 2022 02:16:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6AAD66B0074; Mon, 21 Mar 2022 22:16:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 659916B0075; Mon, 21 Mar 2022 22:16:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4FA3C6B0078; Mon, 21 Mar 2022 22:16:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 3E5746B0074 for ; Mon, 21 Mar 2022 22:16:31 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 08AAD8012D for ; Tue, 22 Mar 2022 02:16:31 +0000 (UTC) X-FDA: 79270408182.11.0213CE3 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf07.hostedemail.com (Postfix) with ESMTP id 635B64000B for ; Tue, 22 Mar 2022 02:16:28 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4KMw6f1gFxzfZW2; Tue, 22 Mar 2022 10:14:50 +0800 (CST) Received: from [10.174.177.76] (10.174.177.76) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Tue, 22 Mar 2022 10:16:22 +0800 Subject: Re: [PATCH v2] mm/mempolicy: fix mpol_new leak in shared_policy_replace To: kernel test robot , , CC: , , , , , References: <20220322083456.16563-1-linmiaohe@huawei.com> <202203220336.VpfVL4ng-lkp@intel.com> From: Miaohe Lin Message-ID: <1c2b6285-1404-4a80-73ec-4949f4eef09e@huawei.com> Date: Tue, 22 Mar 2022 10:16:21 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <202203220336.VpfVL4ng-lkp@intel.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.76] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Authentication-Results: imf07.hostedemail.com; dkim=none; spf=pass (imf07.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 635B64000B X-Stat-Signature: jbgwqg77g1bfpjg1jrygdkhtspd5zrhm X-HE-Tag: 1647915388-672738 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 2022/3/22 4:01, kernel test robot wrote: > Hi Miaohe, > > Thank you for the patch! Yet something to improve: > > [auto build test ERROR on linux/master] > [also build test ERROR on linus/master v5.17] > [cannot apply to hnaz-mm/master next-20220321] > [If your patch is applied to the wrong git tree, kindly drop us a note. > And when submitting patch, we suggest to use '--base' as documented in > https://git-scm.com/docs/git-format-patch] > > url: https://github.com/0day-ci/linux/commits/Miaohe-Lin/mm-mempolicy-fix-mpol_new-leak-in-shared_policy_replace/20220321-200100 > base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 2c271fe77d52a0555161926c232cd5bc07178b39 > config: x86_64-randconfig-a002-20220321 (https://download.01.org/0day-ci/archive/20220322/202203220336.VpfVL4ng-lkp@intel.com/config) > compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 85e9b2687a13d1908aa86d1b89c5ce398a06cd39) > reproduce (this is a W=1 build): > wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross > chmod +x ~/bin/make.cross > # https://github.com/0day-ci/linux/commit/9a91a8a7964a3af0b60f08dc38b7815e5118206a > git remote add linux-review https://github.com/0day-ci/linux > git fetch --no-tags linux-review Miaohe-Lin/mm-mempolicy-fix-mpol_new-leak-in-shared_policy_replace/20220321-200100 > git checkout 9a91a8a7964a3af0b60f08dc38b7815e5118206a > # save the config file to linux build tree > mkdir build_dir > COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash > > If you fix the issue, kindly add following tag as appropriate > Reported-by: kernel test robot > > All errors (new ones prefixed by >>): > >>> mm/mempolicy.c:2745:15: error: incompatible pointer types passing 'atomic_t *' to parameter of type 'refcount_t *' (aka 'struct refcount_struct *') [-Werror,-Wincompatible-pointer-types] > refcount_set(&mpol_new->refcnt, 1); > ^~~~~~~~~~~~~~~~~ > include/linux/refcount.h:134:45: note: passing argument to parameter 'r' here > static inline void refcount_set(refcount_t *r, int n) > ^ > 1 error generated. > Many thanks for report. Commit 4fbd79de2889 ("mm/mempolicy: convert from atomic_t to refcount_t on mempolicy->refcnt") has changed mpol_new->refcnt from atomic_t to refcount_t. So we should use refcount_set instead of atomic_set here. Thanks. > > vim +2745 mm/mempolicy.c > > 2681 > 2682 /* Replace a policy range. */ > 2683 static int shared_policy_replace(struct shared_policy *sp, unsigned long start, > 2684 unsigned long end, struct sp_node *new) > 2685 { > 2686 struct sp_node *n; > 2687 struct sp_node *n_new = NULL; > 2688 struct mempolicy *mpol_new = NULL; > 2689 int ret = 0; > 2690 > 2691 restart: > 2692 write_lock(&sp->lock); > 2693 n = sp_lookup(sp, start, end); > 2694 /* Take care of old policies in the same range. */ > 2695 while (n && n->start < end) { > 2696 struct rb_node *next = rb_next(&n->nd); > 2697 if (n->start >= start) { > 2698 if (n->end <= end) > 2699 sp_delete(sp, n); > 2700 else > 2701 n->start = end; > 2702 } else { > 2703 /* Old policy spanning whole new range. */ > 2704 if (n->end > end) { > 2705 if (!n_new) > 2706 goto alloc_new; > 2707 > 2708 *mpol_new = *n->policy; > 2709 atomic_set(&mpol_new->refcnt, 1); > 2710 sp_node_init(n_new, end, n->end, mpol_new); > 2711 n->end = start; > 2712 sp_insert(sp, n_new); > 2713 n_new = NULL; > 2714 mpol_new = NULL; > 2715 break; > 2716 } else > 2717 n->end = start; > 2718 } > 2719 if (!next) > 2720 break; > 2721 n = rb_entry(next, struct sp_node, nd); > 2722 } > 2723 if (new) > 2724 sp_insert(sp, new); > 2725 write_unlock(&sp->lock); > 2726 ret = 0; > 2727 > 2728 err_out: > 2729 if (mpol_new) > 2730 mpol_put(mpol_new); > 2731 if (n_new) > 2732 kmem_cache_free(sn_cache, n_new); > 2733 > 2734 return ret; > 2735 > 2736 alloc_new: > 2737 write_unlock(&sp->lock); > 2738 ret = -ENOMEM; > 2739 n_new = kmem_cache_alloc(sn_cache, GFP_KERNEL); > 2740 if (!n_new) > 2741 goto err_out; > 2742 mpol_new = kmem_cache_alloc(policy_cache, GFP_KERNEL); > 2743 if (!mpol_new) > 2744 goto err_out; >> 2745 refcount_set(&mpol_new->refcnt, 1); > 2746 goto restart; > 2747 } > 2748 >