Received: by 10.223.185.116 with SMTP id b49csp701836wrg; Wed, 14 Feb 2018 05:47:47 -0800 (PST) X-Google-Smtp-Source: AH8x226I9VVpUkMaABbEwB2wrnde2rlqKxXfS7tqMInEvlNcKQtOz2T8QqglWSCvUJ/Dy8S2eVcY X-Received: by 2002:a17:902:aa95:: with SMTP id d21-v6mr4597948plr.16.1518616067377; Wed, 14 Feb 2018 05:47:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518616067; cv=none; d=google.com; s=arc-20160816; b=R6eAubEzbOEENXJ5VQjOV3G0iyishsje0xN5DNdUp5lwuQSS6AEZeW718521rAcri7 UuuqSzKxXksfa/d4LAmCfcdDH2Den6fqLTPWxEYYA/o8zULrnBcm6tulp19hFfuUdKcT +4TeMshjUHMRd7FLI4kP+JpMq2HOF+dylwxt465hk07XYUUeILI3kY9PbUZt2/HrgI5+ cjzFjQF4BFLZWFuyepFTNYCppezyN7Qw2tZv+mF6KLAup58pDiD2Q51/y7CB4d7NRaNT 1hTcR9KoEGvCYp9iuNeqv47EAo5kyzOoa9j174uRkN+Bs5yC8KNbXqfcf2s1hhni0Mm2 wOFQ== 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=x8c9CJ6kNX0YMg4L9bZvvNest4ZRmynDPnGlyiDAQu0=; b=ITeQGYZBuF0ntc+dLdAfCM+8a6MFMmXwcwFDvSkHV6ckmaxzgBn2jN4ucH65bmb+zK l7/CtQP1g7tgP71Yqu/rNC+yh/6VQfDq9h/BiBAF7AEIWPYuWRzTkug7v5uZfFJ5fITT R4giNV9BQHoTmWmOhJaPS/0xffAv7CaCXUxgRrLYImltzdfJmrS7EAlUUczkwhHDtoMo QVN+Jm/7EMQ6XmUsaR+Cd9erhNYrheaoDG+qDIjHbGIJSx/8TBrjPxMgxb4nijk9oHXE 2w8g7dqvcIh8h/08M6KbsJk1RAu/KFVT9URf3Fg575UVzG7xjPca9oKSuluMRN5W+OUJ aF3w== 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 d16-v6si8964871pll.210.2018.02.14.05.47.32; Wed, 14 Feb 2018 05:47:47 -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; 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 S1030564AbeBNNqP (ORCPT + 99 others); Wed, 14 Feb 2018 08:46:15 -0500 Received: from mx2.suse.de ([195.135.220.15]:58738 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030289AbeBNNqO (ORCPT ); Wed, 14 Feb 2018 08:46:14 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id A2902ACE6; Wed, 14 Feb 2018 13:46:12 +0000 (UTC) Subject: Re: [PATCH v2 1/2] pvcalls-front: introduce a per sock_mapping refcount To: Stefano Stabellini , boris.ostrovsky@oracle.com Cc: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, Stefano Stabellini References: <1518488027-22386-1-git-send-email-sstabellini@kernel.org> From: Juergen Gross Message-ID: <5e34f4f5-faa5-1983-7e7e-a71d4aec80ca@suse.com> Date: Wed, 14 Feb 2018 14:46:11 +0100 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: <1518488027-22386-1-git-send-email-sstabellini@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Language: de-DE Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 13/02/18 03:13, Stefano Stabellini wrote: > Introduce a per sock_mapping refcount, in addition to the existing > global refcount. Thanks to the sock_mapping refcount, we can safely wait > for it to be 1 in pvcalls_front_release before freeing an active socket, > instead of waiting for the global refcount to be 1. > > Signed-off-by: Stefano Stabellini > > --- > Changes in v2: > - fix code style > - nicer checks in pvcalls_front_release > - fix check in pvcalls_enter_sock > --- > drivers/xen/pvcalls-front.c | 193 +++++++++++++++++++------------------------- > 1 file changed, 81 insertions(+), 112 deletions(-) > > diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c > index 4c789e6..163bf8c 100644 > --- a/drivers/xen/pvcalls-front.c > +++ b/drivers/xen/pvcalls-front.c > @@ -60,6 +60,7 @@ struct sock_mapping { > bool active_socket; > struct list_head list; > struct socket *sock; > + atomic_t refcount; > union { > struct { > int irq; > @@ -93,6 +94,34 @@ struct sock_mapping { > }; > }; > > +static inline struct sock_mapping *pvcalls_enter_sock(struct socket *sock) > +{ > + struct sock_mapping *map = NULL; Pointless initializer. > + > + if (!pvcalls_front_dev || > + dev_get_drvdata(&pvcalls_front_dev->dev) == NULL) > + return ERR_PTR(-ENOTCONN); > + > + pvcalls_enter(); > + map = (struct sock_mapping *)sock->sk->sk_send_head; > + if (map == NULL) { > + pvcalls_exit() > + return ERR_PTR(-ENOTSOCK); > + } Sorry for noticing this only now: any reason you don't call pvcalls_enter() only here instead? This would remove the need of calling pvcalls_exit() if map == NULL. I can't see pvcalls_enter() protecting sock->sk->sk_send_head in any way. > + > + atomic_inc(&map->refcount); > + return map; > +} > + > +static inline void pvcalls_exit_sock(struct socket *sock) > +{ > + struct sock_mapping *map = NULL; Pointless initializer again. Juergen