From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754171AbdJILd1 (ORCPT ); Mon, 9 Oct 2017 07:33:27 -0400 Received: from www262.sakura.ne.jp ([202.181.97.72]:61574 "EHLO www262.sakura.ne.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751896AbdJILd0 (ORCPT ); Mon, 9 Oct 2017 07:33:26 -0400 Subject: Re: [PATCH v16 1/5] lib/xbitmap: Introduce xbitmap To: Wei Wang Cc: virtio-dev@lists.oasis-open.org, linux-kernel@vger.kernel.org, qemu-devel@nongnu.org, virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, linux-mm@kvack.org, mst@redhat.com, mhocko@kernel.org, akpm@linux-foundation.org, mawilcox@microsoft.com, david@redhat.com, cornelia.huck@de.ibm.com, mgorman@techsingularity.net, aarcange@redhat.com, amit.shah@redhat.com, pbonzini@redhat.com, willy@infradead.org, liliang.opensource@gmail.com, yang.zhang.wz@gmail.com, quan.xu@aliyun.com References: <1506744354-20979-1-git-send-email-wei.w.wang@intel.com> <1506744354-20979-2-git-send-email-wei.w.wang@intel.com> From: Tetsuo Handa Message-ID: <3b575060-e30b-1afe-96a8-6a9f732d5528@I-love.SAKURA.ne.jp> Date: Mon, 9 Oct 2017 20:30:00 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <1506744354-20979-2-git-send-email-wei.w.wang@intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2017/09/30 13:05, Wei Wang wrote: > /** > + * xb_preload - preload for xb_set_bit() > + * @gfp_mask: allocation mask to use for preloading > + * > + * Preallocate memory to use for the next call to xb_set_bit(). This function > + * returns with preemption disabled. It will be enabled by xb_preload_end(). > + */ > +void xb_preload(gfp_t gfp) > +{ > + if (__radix_tree_preload(gfp, XB_PRELOAD_SIZE) < 0) > + preempt_disable(); > + > + if (!this_cpu_read(ida_bitmap)) { > + struct ida_bitmap *bitmap = kmalloc(sizeof(*bitmap), gfp); > + > + if (!bitmap) > + return; > + bitmap = this_cpu_cmpxchg(ida_bitmap, NULL, bitmap); > + kfree(bitmap); > + } > +} I'm not sure whether this function is safe. __radix_tree_preload() returns 0 with preemption disabled upon success. xb_preload() disables preemption if __radix_tree_preload() fails. Then, kmalloc() is called with preemption disabled, isn't it? But xb_set_page() calls xb_preload(GFP_KERNEL) which might sleep... From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-it0-f71.google.com (mail-it0-f71.google.com [209.85.214.71]) by kanga.kvack.org (Postfix) with ESMTP id 31E296B0069 for ; Mon, 9 Oct 2017 07:31:11 -0400 (EDT) Received: by mail-it0-f71.google.com with SMTP id g128so7981449itb.0 for ; Mon, 09 Oct 2017 04:31:11 -0700 (PDT) Received: from www262.sakura.ne.jp (www262.sakura.ne.jp. [2001:e42:101:1:202:181:97:72]) by mx.google.com with ESMTPS id b125si6359960ioa.188.2017.10.09.04.31.09 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 09 Oct 2017 04:31:10 -0700 (PDT) Subject: Re: [PATCH v16 1/5] lib/xbitmap: Introduce xbitmap References: <1506744354-20979-1-git-send-email-wei.w.wang@intel.com> <1506744354-20979-2-git-send-email-wei.w.wang@intel.com> From: Tetsuo Handa Message-ID: <3b575060-e30b-1afe-96a8-6a9f732d5528@I-love.SAKURA.ne.jp> Date: Mon, 9 Oct 2017 20:30:00 +0900 MIME-Version: 1.0 In-Reply-To: <1506744354-20979-2-git-send-email-wei.w.wang@intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: Wei Wang Cc: virtio-dev@lists.oasis-open.org, linux-kernel@vger.kernel.org, qemu-devel@nongnu.org, virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, linux-mm@kvack.org, mst@redhat.com, mhocko@kernel.org, akpm@linux-foundation.org, mawilcox@microsoft.com, david@redhat.com, cornelia.huck@de.ibm.com, mgorman@techsingularity.net, aarcange@redhat.com, amit.shah@redhat.com, pbonzini@redhat.com, willy@infradead.org, liliang.opensource@gmail.com, yang.zhang.wz@gmail.com, quan.xu@aliyun.com On 2017/09/30 13:05, Wei Wang wrote: > /** > + * xb_preload - preload for xb_set_bit() > + * @gfp_mask: allocation mask to use for preloading > + * > + * Preallocate memory to use for the next call to xb_set_bit(). This function > + * returns with preemption disabled. It will be enabled by xb_preload_end(). > + */ > +void xb_preload(gfp_t gfp) > +{ > + if (__radix_tree_preload(gfp, XB_PRELOAD_SIZE) < 0) > + preempt_disable(); > + > + if (!this_cpu_read(ida_bitmap)) { > + struct ida_bitmap *bitmap = kmalloc(sizeof(*bitmap), gfp); > + > + if (!bitmap) > + return; > + bitmap = this_cpu_cmpxchg(ida_bitmap, NULL, bitmap); > + kfree(bitmap); > + } > +} I'm not sure whether this function is safe. __radix_tree_preload() returns 0 with preemption disabled upon success. xb_preload() disables preemption if __radix_tree_preload() fails. Then, kmalloc() is called with preemption disabled, isn't it? But xb_set_page() calls xb_preload(GFP_KERNEL) which might sleep... -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44061) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1XBC-0003ti-57 for qemu-devel@nongnu.org; Mon, 09 Oct 2017 08:29:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1XB8-00005s-4T for qemu-devel@nongnu.org; Mon, 09 Oct 2017 08:29:06 -0400 Received: from www262.sakura.ne.jp ([2001:e42:101:1:202:181:97:72]:17255) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e1XB7-0008Vu-Me for qemu-devel@nongnu.org; Mon, 09 Oct 2017 08:29:02 -0400 References: <1506744354-20979-1-git-send-email-wei.w.wang@intel.com> <1506744354-20979-2-git-send-email-wei.w.wang@intel.com> From: Tetsuo Handa Message-ID: <3b575060-e30b-1afe-96a8-6a9f732d5528@I-love.SAKURA.ne.jp> Date: Mon, 9 Oct 2017 20:30:00 +0900 MIME-Version: 1.0 In-Reply-To: <1506744354-20979-2-git-send-email-wei.w.wang@intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v16 1/5] lib/xbitmap: Introduce xbitmap List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Wei Wang Cc: virtio-dev@lists.oasis-open.org, linux-kernel@vger.kernel.org, qemu-devel@nongnu.org, virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, linux-mm@kvack.org, mst@redhat.com, mhocko@kernel.org, akpm@linux-foundation.org, mawilcox@microsoft.com, david@redhat.com, cornelia.huck@de.ibm.com, mgorman@techsingularity.net, aarcange@redhat.com, amit.shah@redhat.com, pbonzini@redhat.com, willy@infradead.org, liliang.opensource@gmail.com, yang.zhang.wz@gmail.com, quan.xu@aliyun.com On 2017/09/30 13:05, Wei Wang wrote: > /** > + * xb_preload - preload for xb_set_bit() > + * @gfp_mask: allocation mask to use for preloading > + * > + * Preallocate memory to use for the next call to xb_set_bit(). This function > + * returns with preemption disabled. It will be enabled by xb_preload_end(). > + */ > +void xb_preload(gfp_t gfp) > +{ > + if (__radix_tree_preload(gfp, XB_PRELOAD_SIZE) < 0) > + preempt_disable(); > + > + if (!this_cpu_read(ida_bitmap)) { > + struct ida_bitmap *bitmap = kmalloc(sizeof(*bitmap), gfp); > + > + if (!bitmap) > + return; > + bitmap = this_cpu_cmpxchg(ida_bitmap, NULL, bitmap); > + kfree(bitmap); > + } > +} I'm not sure whether this function is safe. __radix_tree_preload() returns 0 with preemption disabled upon success. xb_preload() disables preemption if __radix_tree_preload() fails. Then, kmalloc() is called with preemption disabled, isn't it? But xb_set_page() calls xb_preload(GFP_KERNEL) which might sleep...