Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4308490imu; Fri, 30 Nov 2018 14:53:04 -0800 (PST) X-Google-Smtp-Source: AFSGD/Xe2C9mWVBkIPX6SjhHweo/9EOa5AQeHeonZurr4dkHRe+HePwdsJvuxLSwPTenkTp8eZjX X-Received: by 2002:a63:6984:: with SMTP id e126mr6376743pgc.143.1543618384834; Fri, 30 Nov 2018 14:53:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543618384; cv=none; d=google.com; s=arc-20160816; b=gArhqw43MO6k6qLoUGM7yXKvdm6l3XMeF/6045aXnUzGVHnlVDigCQ2bw23ipC1ehd h1sSYMYzFJ5u7F4/ScPWGTVlYRcg/T6wrG9CskakqqDAIFXFEPAGTI1N0+HKUCMQwRJy pR5VeMRMPyacaUKsH1LA8wTfOIEYYzfsz+7vkSfGumpGiBAFlb/ElQHfaBM8MU0l0uqn f0rXkeOn84NGul/sHvZivhdfgHUkVfAQOrEe62a+1E8Xa4Smd2KjXXUaaUXGe9mh2ibd yWrxH4Iar0plr0nZsdKF69e+hh/HZJzbJ7PPWOnVpK/KxGzEWbFcZS0JEty1HiDATHh/ nLMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature; bh=0mp5ZCibE6wTx2eNeua1uWw4Aw6u+GYXEpQyzPmCuBk=; b=LJs3Jye8a4ovSaTpU12ZT4D0+C+FMcQUc6U1qFPmMtLbM1M/gxZhXbT4/QK3iupbEY K8b/35u5lr4Qt+0wXNjOcjU98rduQiFHQapdJMpmJV8wmGQRPzZBDYEsuBmskZeeqDaB LeCFLqCTnUHDLCF1TdrEUTScM9XpY9R4CheQSC5Ke1H9XAhsjHUP+b52LV/POccmQCWH aE0FT0hR/ova5BO/SJjkfWxa+taV+icLfdxVLNaLLfLGEN0BeOYLJlslroekRX/Eyf/1 10KaKIVKXWD3lCkLA+4SVorhmrn+e0CKMv/IdMfTQwbcLvBknBmOBZUBBnsh9KzJmAtc YX5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1UXdihqh; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q10si6021330pll.221.2018.11.30.14.52.50; Fri, 30 Nov 2018 14:53:04 -0800 (PST) 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=@kernel.org header.s=default header.b=1UXdihqh; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726736AbeLAKBz (ORCPT + 99 others); Sat, 1 Dec 2018 05:01:55 -0500 Received: from mail.kernel.org ([198.145.29.99]:60688 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726474AbeLAKBz (ORCPT ); Sat, 1 Dec 2018 05:01:55 -0500 Received: from localhost (c-67-164-102-47.hsd1.ca.comcast.net [67.164.102.47]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EB33C2082F; Fri, 30 Nov 2018 22:51:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543618263; bh=d/wwN8QyojM8TZ60cr9NqkDeCyYeIxy46fwdS1usIqE=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=1UXdihqhSSK3ld4zuanFaipdLELEBxjcR5kVIMcsOaNyL1iXpQmaKOxIo0FwAUnNH c+OtlZ0jKgWH26uD/TbYToZ7PiRrzEp3/jEWBmqFsQ1wxl2Hztg3Swmo3/4ocOgkkC ZaaBSJ36t3ygMTCdrSD2u2Vwn8x9UAMVSYi1uRLk= Date: Fri, 30 Nov 2018 14:51:01 -0800 (PST) From: Stefano Stabellini X-X-Sender: sstabellini@sstabellini-ThinkPad-X260 To: Boris Ostrovsky cc: Wen Yang , jgross@suse.com, sstabellini@kernel.org, xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, zhong.weidong@zte.com.cn, Julia Lawall Subject: Re: [PATCH v3] pvcalls-front: Avoid __get_free_pages(GFP_KERNEL) under spinlock In-Reply-To: <810c02f4-4436-79fb-5da1-0cf80f8486d1@oracle.com> Message-ID: References: <20181130110107.31468-1-wen.yang99@zte.com.cn> <810c02f4-4436-79fb-5da1-0cf80f8486d1@oracle.com> User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 30 Nov 2018, Boris Ostrovsky wrote: > On 11/30/18 6:01 AM, Wen Yang wrote: > > The problem is that we call this with a spin lock held. > > The call tree is: > > pvcalls_front_accept() holds bedata->socket_lock. > > -> create_active() > > -> __get_free_pages() uses GFP_KERNEL > > > > The create_active() function is only called from pvcalls_front_accept() > > with a spin_lock held, The allocation is not allowed to sleep and > > GFP_KERNEL is not sufficient. > > > > This issue was detected by using the Coccinelle software. > > > > v2: Add a function doing the allocations which is called > > outside the lock and passing the allocated data to > > create_active(). > > v3: Use the matching deallocators i.e., free_page() > > and free_pages(), respectively. > > > > Suggested-by: Juergen Gross > > Signed-off-by: Wen Yang > > CC: Julia Lawall > > CC: Boris Ostrovsky > > CC: Juergen Gross > > CC: Stefano Stabellini > > CC: xen-devel@lists.xenproject.org > > CC: linux-kernel@vger.kernel.org > > --- > > drivers/xen/pvcalls-front.c | 71 ++++++++++++++++++++++++++++++------- > > 1 file changed, 59 insertions(+), 12 deletions(-) > > > > diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c > > index 2f11ca72a281..a26f416daf46 100644 > > --- a/drivers/xen/pvcalls-front.c > > +++ b/drivers/xen/pvcalls-front.c > > @@ -335,7 +335,43 @@ int pvcalls_front_socket(struct socket *sock) > > return ret; > > } > > > > -static int create_active(struct sock_mapping *map, int *evtchn) > > +struct sock_mapping_active_ring { > > + struct pvcalls_data_intf *ring; > > + RING_IDX ring_order; > > + void *bytes; > > +}; > > + > > +static int alloc_active_ring(struct sock_mapping_active_ring *active_ring) > > +{ > > + active_ring->ring = NULL; > > This is not necessary. > > > + active_ring->bytes = NULL; > > + > > + active_ring->ring = (struct pvcalls_data_intf *) > > + __get_free_page(GFP_KERNEL | __GFP_ZERO); > > + if (active_ring->ring == NULL) > > + goto out_error; > > + active_ring->ring_order = PVCALLS_RING_ORDER; > > + active_ring->bytes = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, > > + PVCALLS_RING_ORDER); > > + if (active_ring->bytes == NULL) > > + goto out_error; > > + > > + return 0; > > + > > +out_error: > > + free_pages((unsigned long)active_ring->bytes, active_ring->ring_order); > > + free_page((unsigned long)active_ring->ring); > > + return -ENOMEM; > > +} > > + > > > > > @@ -397,6 +427,7 @@ int pvcalls_front_connect(struct socket *sock, struct sockaddr *addr, > > struct sock_mapping *map = NULL; > > struct xen_pvcalls_request *req; > > int notify, req_id, ret, evtchn; > > + struct sock_mapping_active_ring active_ring; > > > > if (addr->sa_family != AF_INET || sock->type != SOCK_STREAM) > > return -EOPNOTSUPP; > > @@ -406,15 +437,21 @@ int pvcalls_front_connect(struct socket *sock, struct sockaddr *addr, > > return PTR_ERR(map); > > > > bedata = dev_get_drvdata(&pvcalls_front_dev->dev); > > + ret = alloc_active_ring(&active_ring); > > Why not just alloc_active_ring(map)? Yes, I think it would be better to pre-populate map (struct sock_mapping), rather than introducing one more new struct (struct sock_mapping_active_ring).